有一个ArrayList>,如何序列化?
ArrayList<ArrayList<MyPoint>> polygons;
try {
FileOutputStream fileOut = openFileOutput("polygons.ser", MODE_PRIVATE);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(pv.polygons);
out.close();
fileOut.close();
Log.d("Polygons Output", pv.polygons.toString());
Log.d("Polygons Output Out", out.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
FileInputStream fileIn = openFileInput("polygons.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
ArrayList<ArrayList<MyPoint>> arr = new ArrayList<>();
pv.polygons = (ArrayList<ArrayList<MyPoint>>) in.readObject();
in.close();
fileIn.close();
} catch (IOException io) {
io.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Log.d显示[[Point(0,0),....]]的数组列表。
outputStream位于onSaveInstance中,inputStream位于onCreate()中。 MyPoint扩展了Point实现Serializable ......
为什么不起作用?