Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2853 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Probleme de lecture d'objet[RESOLU]

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme de lecture d'objet[RESOLU]

n°1432974
java_B
Posté le 29-08-2006 à 11:31:29  profilanswer
 

Bonjour,
Voila mon problème :
J’essaye de lire des objets a partir d’un fichier, voila  la partie du code qui normalement me permet de le faire :
 
fis = new FileInputStream(fich.dat);
ois = new ObjectInputStream(fis);
page = (Page)(ois.readObject());
 
mais le problem est quand  je crée une instance de  FileInputStream la taille du fichier « fich.dat » passe de 3 ko a  0 ko et par conséquence lors de la lecture de l’objet j’ai une exception : EOFexception .
est ce que quelqu’un peut m’aider ?


Message édité par java_B le 21-09-2006 à 14:37:00
mood
Publicité
Posté le 29-08-2006 à 11:31:29  profilanswer
 

n°1438588
java_B
Posté le 07-09-2006 à 16:59:20  profilanswer
 

Répondez moi SVP

n°1438765
lonely
Posté le 07-09-2006 à 23:25:38  profilanswer
 

A priori ton code est bon.
Ajoute ois.close() après avoir créer ton objet.
Il faudrait regarder comment tu as créer ton objet avec ObjectOutputStream ?.
 
http://java.sun.com/j2se/1.4.2/doc [...] tream.html
 
Any attempt to read object data which exceeds the boundaries of the custom data written by the corresponding writeObject method will cause an OptionalDataException to be thrown with an eof field value of true. Non-object reads which exceed the end of the allotted data will reflect the end of data in the same way that they would indicate the end of the stream: bytewise reads will return -1 as the byte read or number of bytes read, and primitive reads will throw EOFExceptions. If there is no corresponding writeObject method, then the end of default serialized data marks the end of the allotted data.
 
Primitive and object read calls issued from within a readExternal method behave in the same manner--if the stream is already positioned at the end of data written by the corresponding writeExternal method, object reads will throw OptionalDataExceptions with eof set to true, bytewise reads will return -1, and primitive reads will throw EOFExceptions. Note that this behavior does not hold for streams written with the old ObjectStreamConstants.PROTOCOL_VERSION_1 protocol, in which the end of data written by writeExternal methods is not demarcated, and hence cannot be detected.

n°1438890
java_B
Posté le 08-09-2006 à 10:25:02  profilanswer
 

Merci pour ta réponse;
Voila comment j'ai créée mon objet avec ObjectOutputStream :
 
public void SaveTempoWorkSpace(){
  FileOutputStream fos;
  ObjectOutputStream oos;
   
for (int i=0;i<this.getZoneDessin().getPages().size();i++){
fos=null;
os=null;
Page page = (Page)(this.getZoneDessin().getPages()).get(i);
try {
fos = new FileOutputStream("."+this.SEPARATOR+
                              this.getTempoworkSpace()+
                                 this.SEPARATOR+
                                 page.getProjet()+
   this.SEPARATOR+
   page.getNom());
     
} catch (FileNotFoundException e) {}  
try {
  oos = new ObjectOutputStream(fos);
} catch (IOException e) {}
try {
oos.writeObject(page);
} catch (IOException e) {}
try {
oos.flush();
oos.close();
fos.flush();
fos.close();
} catch (IOException e) {}
}
}
}

n°1444235
java_B
Posté le 18-09-2006 à 16:58:49  profilanswer
 

est ce que qq peut me répondre

n°1444284
souk
Tourist
Posté le 18-09-2006 à 17:57:12  profilanswer
 

tu pourrais commencer par faire quelque chose quand il y a une exception [:pingouino]
deja, commence par afficher les exceptions a coup de printStackTrace, tu verras si tout se passe bien ou pas. apres on avisera

n°1444348
lonely
Posté le 18-09-2006 à 20:08:13  profilanswer
 

for (int i=0;i<this.getZoneDessin().getPages().size();i++){
...
Page page = (Page)(this.getZoneDessin().getPages()).get(i);  
...
fos = new FileOutputStream("."+this.SEPARATOR+...
 
Tu n'essayerais pas de mettre plusieurs objets dans ton fichier ?

n°1444643
java_B
Posté le 19-09-2006 à 14:48:29  profilanswer
 

java.io.EOFException
 at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
 at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
 at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
 at java.io.ObjectInputStream.<init>(Unknown Source)
 at ihm.GestionProjet.load_arbo(GestionProjet.java:277)
 at ihm.GestionProjet.load_arbo(GestionProjet.java:258)
 at ihm.GestionProjet.loadJTree(GestionProjet.java:360)
 at ihm.Edit_RDP.<init>(Edit_RDP.java:166)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at org.eclipse.ve.internal.java.vce.launcher.remotevm.JFCLauncher.launch(JFCLauncher.java:56)
 at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:77)
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at org.eclipse.ve.internal.java.vce.launcher.remotevm.JFCLauncher.launch(JFCLauncher.java:56)
 at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:77)
Caused by: java.lang.NullPointerException
 at ihm.GestionProjet.load_arbo(GestionProjet.java:280)
 at ihm.GestionProjet.load_arbo(GestionProjet.java:258)
 at ihm.GestionProjet.loadJTree(GestionProjet.java:360)
 at ihm.Edit_RDP.<init>(Edit_RDP.java:166)
 ... 6 more
IWAV0052E Invocation Target Exception creating ihm.Edit_RDP
 
voila ce que donne un printStackTrace

n°1444646
java_B
Posté le 19-09-2006 à 14:52:00  profilanswer
 

lonely a dit :
Tu n'essayerais pas de mettre plusieurs objets dans ton fichier ?
 
non lonely  parce que  je change à chaque itération de ma boucle le pramétre d'etrée de fos

n°1444655
souk
Tourist
Posté le 19-09-2006 à 15:06:22  profilanswer
 

Code :
  1. Caused by: java.lang.NullPointerException
  2. at ihm.GestionProjet.load_arbo(GestionProjet.java:280)


 
voila

mood
Publicité
Posté le 19-09-2006 à 15:06:22  profilanswer
 

n°1444696
java_B
Posté le 19-09-2006 à 15:56:51  profilanswer
 

Merci souk pour ta réponse mais malheureusement ça règle pas mon problème.
le problème est quand  je crée une instance de  FileInputStream la taille du fichier « fich.dat » passe de 3 ko a  0 ko et par conséquence lors de la lecture de l’objet j’ai une exception : EOFexception .  
Déjà la première exception est : java.io.EOFException  
Essaye de relire mon problème  
Merci

n°1444745
souk
Tourist
Posté le 19-09-2006 à 16:56:07  profilanswer
 

est ce que chaque FilOutputStream est bien flushé et closé ? pas d'exception à ce niveau non plus ?

n°1445032
java_B
Posté le 20-09-2006 à 09:29:05  profilanswer
 

souk a écrit :

est ce que chaque FilOutputStream est bien flushé et closé ? pas d'exception à ce niveau non plus ?


oui, chaque FileOutputStream est bien flushé et closé

n°1445780
java_B
Posté le 21-09-2006 à 14:34:12  profilanswer
 

Le problème que j'avais, était due  au fait que le paramètre d'entrée de  FileInputStream qui est un String  et qui représente le chemin de mon fichier commençait par un chiffre (un peut bizarre) mais rien qu'on changeant le nom de mon fichier par un autre qui commence par une lettre ça marche.
Je vous remercie pour votre aide.  :D


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Probleme de lecture d'objet[RESOLU]

 

Sujets relatifs
[Résolu] Listbox -> Comment vérifier qu'un élement est selectionné ?Probleme d'affichage avec firefox
Problème avec VB 6![RESOLU]Copier tous les fichiers d'un repertoire en vb6
[Resolu] Débutant swing : interface graphique dynamique[RESOLU] Excel --> powerpoint
[javascript/html/php]Problème Tableau html / Back IEproblème : méthode Cells de l'objet global a échoué
[RESOLU] Partager Wamp 
Plus de sujets relatifs à : Probleme de lecture d'objet[RESOLU]


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR