Bonjour à tous. J'ai un petit problème pour sérialiser mon arrayList et pour la récupérer.
Mon code :
Quelqu'un aurait une idée ? Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public static void serialiser(ArrayList<Point> alp, String path) { ObjectOutputStream serialise; try { serialise = new ObjectOutputStream(new FileOutputStream(path)); serialise.writeInt(alp.size()); for (int i =0; i < alp.size(); i++){ serialise.writeObject(alp.get(i)); serialise.flush(); } serialise.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static ArrayList<Point> deserialiser(String path) { ArrayList<Point> retour = new ArrayList<Point>(); ObjectInputStream deserialise; try { deserialise = new ObjectInputStream(new FileInputStream(path)); for (int i = 0; i < deserialise.readInt(); i++){ Point p = (Point)deserialise.readObject(); retour.add(p); } } catch (StreamCorruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return retour; }
Partager