Advertisement
Guest User

peppino info

a guest
May 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.io.;
  2. public class Scrivisufile
  3. {
  4. public static void main(String args[])
  5. {
  6. Persona p1,p2,p3;
  7. p1=new Persona("mario",18);
  8. p2=new Persona("luca",17);
  9. p3=new Persona("marco",20);
  10.  
  11. try
  12. {
  13. File Output Stream f=new File Output Stream( persone.dat);
  14. Object Output Stream fout= new Object Output Stream (f);
  15. fout.write Object (p1);
  16. fout.write Object (p2);
  17. fout.write Object (p3);
  18. fout.flush();
  19. f.close();
  20. }
  21. catch( exception e)
  22. {
  23. System.out.println("eccezione:"+e.getMessage() );
  24. }
  25.  
  26.  
  27.  
  28. try
  29. {
  30. File Input Stream f1= New File Input Stream ("persone.dat");
  31. Object Input Stream fine= new Object Input Stream (f1);
  32. //ciclo per leggere i dati
  33. while (true)
  34. {
  35. try
  36. {
  37. p=(Persona) fin.read Object();
  38. System.out,println("\n nome:"+p.get_nome() );
  39. System.out,println("\n eta:"+p.get_eta() );
  40. }
  41. catch(EOFException e)
  42. {
  43. break;
  44. }
  45. }
  46. f1.close();
  47. }
  48. catch(Exeption e)
  49. {
  50. System.out.println(eccezione:"+e.get Message() );
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement