1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
...
Compte testCompte= new CompteCourant("DUSCHMOLL", "Gérard");
FileOutputStream fos=null;
ObjectOutputStream myOut=null;
try{ fos= new FileOutputStream("test2.dat");
myOut= new ObjectOutputStream(fos);
myOut.writeObject(testCompte);
myOut.flush();
}
catch(FileNotFoundException fnfe){System.out.println("Le fichier mentionné n'a pu être trouvé !");}
catch(IOException e1){System.out.println("Une erreur d'entrée sortie s'est produite !!");}
finally{ if(myOut!=null){myOut.close();}
}
FileInputStream fis=null;
ObjectInputStream myIn=null;
try{
fis=new FileInputStream("test2.dat");
myIn= new ObjectInputStream(fis);
Hashtable<String, Compte> sortie= new Hashtable<String, Compte>();
//c'est ce cast-là qui est refusé :
sortie = (Hashtable<String, Compte>)myIn.readObject();
System.out.println(sortie.keySet());
}
catch(FileNotFoundException fnfe){System.out.println("Le fichier mentionné n'a pu être trouvé !");}
catch(ClassNotFoundException cnfe){System.out.println("classe non trouvée !!");}
catch(IOException e1){System.out.println("Une erreur d'entrée sortie s'est produite !!");}
finally{ if(myIn!=null){myIn.close();}
} |
Partager