Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package archivos;
- import java.io.EOFException;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- public class Main {
- public static void main(String[] args)
- {
- // Temperatura.escribir();
- // Temperatura.leer();
- try
- {
- FileOutputStream fileOutputStream = new FileOutputStream("personas.dat");
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
- objectOutputStream.writeObject(new Persona("gonzalo"));
- objectOutputStream.writeObject(new Persona("gabriel"));
- objectOutputStream.writeObject(new Persona("gustavo"));
- objectOutputStream.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- try
- {
- FileInputStream fileInputStream = new FileInputStream("personas.dat");
- ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
- Persona aux ;
- while ((aux = (Persona)inputStream.readObject())!=null)
- {
- System.out.println(aux.toString());
- }
- inputStream.close();
- }
- catch (EOFException e)
- {
- // TODO: handle exception
- }
- catch (IOException ex)
- {
- }
- catch (ClassNotFoundException ex)
- {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement