Skip to content

Instantly share code, notes, and snippets.

@JuanjoSalvador
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanjoSalvador/95d4cc5cf678f11d2c6c to your computer and use it in GitHub Desktop.
Save JuanjoSalvador/95d4cc5cf678f11d2c6c to your computer and use it in GitHub Desktop.
Lee objetos del fichero escrito con ObjectWriter.java
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.");
}
}
}
@JuanjoSalvador
Copy link
Author

El método toString() detallado

public String toString() { return this.parametro_1 + " " + this.parametro_2 + " " + this.parametro_3; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment