Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sem10;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author JA
- */
- public class Sem10 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- FileInputStream fis;
- try {
- fis = new FileInputStream("data.dat");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Sem10.class.getName()).log(Level.SEVERE, null, ex);
- }
- ObjectInputStream ois = new ObjectInputStream(fis);
- osoby = (ArrayList<Osoba>) ois.readObject();
- ois.close();
- } catch (IOException ex){
- System.out.println("Chyba souboru");
- ArrayList<Osoba> osoby = new ArrayList();
- osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
- osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
- osoby.add(new Osoba("Jan", "Loufek", "Liberec", "1984", "180"));
- try {
- FileOutputStream fos = new FileOutputStream("data.dat");
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(osoby);
- oos.close();
- } catch (IOException ex) {
- Logger.getLogger(Sem10.class.getName()).log(Level.SEVERE, null, ex);
- }
- Object[] os=osoby.toArray();
- System.out.println(Arrays.toString(os));
- Arrays.sort(os);
- System.out.println(Arrays.toString(os));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement