Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.;
- public class Scrivisufile
- {
- public static void main(String args[])
- {
- Persona p1,p2,p3;
- p1=new Persona("mario",18);
- p2=new Persona("luca",17);
- p3=new Persona("marco",20);
- try
- {
- File Output Stream f=new File Output Stream( persone.dat);
- Object Output Stream fout= new Object Output Stream (f);
- fout.write Object (p1);
- fout.write Object (p2);
- fout.write Object (p3);
- fout.flush();
- f.close();
- }
- catch( exception e)
- {
- System.out.println("eccezione:"+e.getMessage() );
- }
- try
- {
- File Input Stream f1= New File Input Stream ("persone.dat");
- Object Input Stream fine= new Object Input Stream (f1);
- //ciclo per leggere i dati
- while (true)
- {
- try
- {
- p=(Persona) fin.read Object();
- System.out,println("\n nome:"+p.get_nome() );
- System.out,println("\n eta:"+p.get_eta() );
- }
- catch(EOFException e)
- {
- break;
- }
- }
- f1.close();
- }
- catch(Exeption e)
- {
- System.out.println(eccezione:"+e.get Message() );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement