Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package sem10;
  8.  
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.io.ObjectInputStream;
  14. import java.io.ObjectOutputStream;
  15. import java.util.ArrayList;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18.  
  19. /**
  20.  *
  21.  * @author JA
  22.  */
  23. public class Sem10 {
  24.  
  25.     /**
  26.      * @param args the command line arguments
  27.      */
  28.     public static void main(String[] args) {
  29.         // TODO code application logic here
  30.        
  31.  
  32.             FileInputStream fis;
  33.             try {
  34.                 fis = new FileInputStream("data.dat");
  35.             } catch (FileNotFoundException ex) {
  36.                 Logger.getLogger(Sem10.class.getName()).log(Level.SEVERE, null, ex);
  37.             }
  38.             ObjectInputStream ois = new ObjectInputStream(fis);
  39.             osoby = (ArrayList<Osoba>) ois.readObject();
  40.             ois.close();
  41.     } catch (IOException ex){
  42.     System.out.println("Chyba souboru");
  43.        
  44.        
  45.         ArrayList<Osoba> osoby = new ArrayList();
  46.         osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
  47.         osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
  48.         osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
  49.        
  50.        
  51.         try {
  52.             FileOutputStream fos = new FileOutputStream("data.dat");
  53.             ObjectOutputStream oos = new ObjectOutputStream(fos);
  54.             oos.writeObject(osoby);
  55.             oos.close();
  56.         } catch (IOException ex) {
  57.             Logger.getLogger(Sem10.class.getName()).log(Level.SEVERE, null, ex);
  58.         }
  59.        
  60.         Object[] os=osoby.toArray();
  61.        
  62.         System.out.println(Arrays.toString(os));
  63.         Arrays.sort(os);
  64.         System.out.println(Arrays.toString(os));
  65.        
  66.     }
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement