Last active
August 29, 2015 14:15
-
-
Save JuanjoSalvador/95d4cc5cf678f11d2c6c to your computer and use it in GitHub Desktop.
Lee objetos del fichero escrito con ObjectWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class ObjectReader { | |
public static void leerRegistro() { | |
try { | |
try (FileInputStream fis = new FileInputStream("/home/USER/registro.txt")) { | |
ObjectInputStream ois = new ObjectInputStream(fis); | |
while (fis.available() > 0) { | |
Objeto registro = (Objeto)ois.readObject(); | |
System.out.println(registro.toString() + "\n"); | |
fis.skip(4); | |
} | |
fis.close(); | |
} | |
} catch (IOException ex) { | |
// ex.printStackTrace(); | |
System.out.println("Ocurrió un error IO."); | |
} catch (ClassNotFoundException cnfex) { | |
// cnfex.printStackTrace(); | |
System.out.println("Ocurrió un error CNF."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
El método
toString()
detalladopublic String toString() { return this.parametro_1 + " " + this.parametro_2 + " " + this.parametro_3; }