Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream("objetos.data"));
- for (int i=0; i<5; i++){
- Persona p = new Persona(i);
- oos.writeObject(p);
- }
- oos.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- ObjectInputStream ois;
- try {
- ois = new ObjectInputStream (new FileInputStream("objetos.data"));
- try {
- Object aux = ois.readObject();
- while (aux!=null){
- if (aux instanceof Persona){
- System.out.println(aux);
- }
- ois.readObject();
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment