A voir également:
- [Java] serialisation!
- Waptrick java football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Jeux java itel football - Télécharger - Jeux vidéo
- Jeux java itel 5360 ✓ - Forum Mobile
- Télécharger jeux java gameloft gratuit - Forum Mobile
2 réponses
Utilisateur anonyme
30 août 2009 à 19:36
30 août 2009 à 19:36
Salut,
Sérialiser:
Désérialiser:
Cordialement,
Dan
Sérialiser:
try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("nomDuFichier.sav")); out.writeObject(monObject1); out.writeObject(monObject2); out.close(); } catch( IOException e ) {....}
Désérialiser:
try { ObjectInputStream in = new ObjectInputStream(new FileInputStream("nomDuFichier.sav")); MonObject1 monObject1 = (MonObject1)in.readObject(); MonObject2 monObject2 = (MonObject2)in.readObject(); in.close(); } catch( ClassNotFoundException e1 ) {....} catch( IOException e2 ) {....}
Cordialement,
Dan
Salut,
ici MonObject1 et MonObject2 sont 2 classes différentes.
Dans votre exemple de sérialisation, complétons comme ceci:
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("nomDuFichier.sav"));
Personne monObject1 = new Personne ("personne1", "prenom1");
Personne monObject2 = new Personne ("personne2", "prenom2");
out.writeObject(monObject1);
out.writeObject(monObject2);
out.close();
}
catch( IOException e )
{....}
2 questions me viennent : 1 seule d'instance de la classe Personne a été sérialisée? ou les 2?
Autre chose, si les 2 ont été sérialisées, comment récupérer mes 2 objets?
En faisant:
Personne p1 = in.ReadObject();
Personne p2 = in.ReadObject();
?
Dans ce cas, comment récupérer n entrées?
Serait t'il possible de faire quelque chose du genre:
while (Personne p = in.ReadObject()) {
...
}
?
ici MonObject1 et MonObject2 sont 2 classes différentes.
Dans votre exemple de sérialisation, complétons comme ceci:
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("nomDuFichier.sav"));
Personne monObject1 = new Personne ("personne1", "prenom1");
Personne monObject2 = new Personne ("personne2", "prenom2");
out.writeObject(monObject1);
out.writeObject(monObject2);
out.close();
}
catch( IOException e )
{....}
2 questions me viennent : 1 seule d'instance de la classe Personne a été sérialisée? ou les 2?
Autre chose, si les 2 ont été sérialisées, comment récupérer mes 2 objets?
En faisant:
Personne p1 = in.ReadObject();
Personne p2 = in.ReadObject();
?
Dans ce cas, comment récupérer n entrées?
Serait t'il possible de faire quelque chose du genre:
while (Personne p = in.ReadObject()) {
...
}
?