Guest User

Untitled

a guest
Mar 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package serializacjaobiektow;
  2.  
  3.  
  4.  
  5.  
  6. import java.io.*;
  7.  
  8. public class SerializacjaObiektow
  9. {
  10.  
  11.  
  12. public static void main(String[] args)
  13. {
  14. Towar[] towar = new Towar[3];
  15.  
  16. towar[0] = new Towar();
  17. towar[1] = new Towar(29.0,"Video kurs Java");
  18. towar[2] = new Towar(39.0,"Video kurs C++", 2008, 11, 21);
  19.  
  20.  
  21. try
  22. {
  23. ObjectOutputStream outS = new ObjectOutputStream(new FileOutputStream("baza.txt"));
  24.  
  25. outS.writeObject(towar);
  26.  
  27. outS.close();
  28.  
  29. ObjectInputStream inS = new ObjectInputStream(new FileInputStream("baza.txt"));
  30.  
  31. Towar[] a = (Towar[])inS.readObject();
  32.  
  33. for(int i=0;i<a.length;i++)
  34. {
  35. System.out.println(a[i].pobierzNazwe());
  36.  
  37. }
  38.  
  39.  
  40. inS.close();
  41.  
  42.  
  43. }
  44. catch (IOException e)
  45. {
  46. System.out.println(e.getMessage());
  47.  
  48. }
  49. catch (ClassNotFoundException e)
  50. {
  51. System.out.println(e.getMessage());
  52.  
  53. }
  54.  
  55. }
  56.  
  57. }
Add Comment
Please, Sign In to add comment