Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package serializacjaobiektow;
- import java.io.*;
- public class SerializacjaObiektow
- {
- public static void main(String[] args)
- {
- Towar[] towar = new Towar[3];
- towar[0] = new Towar();
- towar[1] = new Towar(29.0,"Video kurs Java");
- towar[2] = new Towar(39.0,"Video kurs C++", 2008, 11, 21);
- try
- {
- ObjectOutputStream outS = new ObjectOutputStream(new FileOutputStream("baza.txt"));
- outS.writeObject(towar);
- outS.close();
- ObjectInputStream inS = new ObjectInputStream(new FileInputStream("baza.txt"));
- Towar[] a = (Towar[])inS.readObject();
- for(int i=0;i<a.length;i++)
- {
- System.out.println(a[i].pobierzNazwe());
- }
- inS.close();
- }
- catch (IOException e)
- {
- System.out.println(e.getMessage());
- }
- catch (ClassNotFoundException e)
- {
- System.out.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment