|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Jul 2003
Messaggi: 23
|
Problema lettura file strutturati [Java]
Salve, come da titolo ho un problema nella lettua di file strutturati.
La lettura avviene correttamente solo se nel file strutturato è stata effettuata una sola scrittura.Se invece, con modalità append, vengono aggiunti nuovi dati al file strutturato, la lettura (che avviene fino a generazione di eccezione per raggiungimento della fine del file) comporta la lettura delle informazioni inserite nella prima mscrittura, e nulla di più. pwer la scrittura il codice è il seguente FileOutputStream f = new FileOutputStream ("myfile.dat",true); ObjectOutputStream fOut = new ObjectOutputStream (f); fOut.writeObject(myObject); fOut.flush(); f.close(); per la lettura myClass newObject; try{ FileInputStream f = new FileInputStream ("myfile.dat"); ObjectInputStream fIN = new ObjectInputStream (giocate); while(true) try{ newObject = (myClass) giocateIN.readObject(); System.out.println(newObject.num1 +" "+ newObject.num2); } catch(EOFException e){ //interrompe il ciclo break; } f.close(); } catch(Exception e){ System.out.println("ERROR"+e.getCause()); } FileOutputStream f = new FileOutputStream ("myfile.dat",true); ObjectOutputStream fOut = new ObjectOutputStream (f); fOut.writeObject(myObject); fOut.flush(); f.close(); ES. 2 3 3 6 7 8 Quando leggo nel file ottengo 2 3 ERRORNull Graziw |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:43.