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 35 36 37 38 39
| public abstract class TestSerialisation {
public static void main(String[] args) {
Truc c1 = new Truc("Truc1");
Truc c2 = new Truc("Truc2");
Truc c3 = new Truc("Truc3");
Truc c4 = new Truc("Truc4");
Truc c5 = new Truc("Truc5");
Document d1 = new Document("Doc1", 1, c1);
Document d2 = new Document("Doc2", 2, c2);
Document d3 = new Document("Doc3", 3, c3);
Document d4 = new Document("Doc4", 4, c4);
Document d5 = new Document("Doc5", 5, c5);
List<Document> doc1 = new ArrayList<Document>();
doc1.add(d1);
doc1.add(d2);
doc1.add(d3);
List<Document> doc2 = new ArrayList<Document>();
doc2.add(d4);
doc2.add(d5);
PorteDocument p1 = new PorteDocument("PorteDoc1", doc1);
PorteDocument p2 = new PorteDocument("Portedoc2", doc2);
Hashtable<String, PorteDocument> porteDocuments = new Hashtable<String, PorteDocument>();
porteDocuments.put(p1.getName(), p1);
porteDocuments.put(p2.getName(), p2);
try {
FileOutputStream fos = new FileOutputStream("PorteDocuments.serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.flush();
oos.writeObject(porteDocuments);
oos.close();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} |
Partager