Advertisement
gonzalob

Untitled

May 11th, 2020
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public static void main(String[] args)
  2.     {
  3.         Avion a1 = new Avion("Boeing", "777X", "comercial" , 384);
  4.         Avion a2 = new Avion("Boeing", "F-18", " caza polivalente" , 1);
  5.        
  6.         File file = new File("file2.dat");
  7.         boolean append = file.exists(); // if file exists then append, otherwise create new
  8.  
  9.         try
  10.         {
  11.             FileOutputStream fout = new FileOutputStream(file, append);
  12.             AppendableObjectOutputStream oout = new AppendableObjectOutputStream(fout, append);
  13.             oout.writeObject(a1);
  14.             oout.writeObject(a2);
  15.             mostrarArchivo("file2.dat");
  16.         }
  17.         catch (EOFException e)
  18.         {
  19.             //es un error pero no pasa nada
  20.         }
  21.         catch (FileNotFoundException e)
  22.         {
  23.             e.printStackTrace();
  24.         } catch (IOException e) {
  25.             e.printStackTrace();
  26.         } catch (ClassNotFoundException e) {
  27.             // TODO Auto-generated catch block
  28.             e.printStackTrace();
  29.         }
  30.  
  31.      
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement