【发布时间】:2013-04-24 12:59:12
【问题描述】:
我有一个 Shape 数组:
Shape[] myshape = new Shape[13];
如何将其保存到文件中?
我找到了一些代码:
String fileName = "file.test";
BufferedOutputStream bs = null;
try {
FileOutputStream fs = new FileOutputStream(new File(fileName));
bs = new BufferedOutputStream(fs);
bs.write(byte_array);
bs.close();
bs = null;
} catch (Exception e) {
e.printStackTrace()
}
if (bs != null) try { bs.close(); } catch (Exception e) {}
但是代码只适用于字节数组,谁能帮帮我?
【问题讨论】:
-
您需要使您的 Shape 类可序列化。见:stackoverflow.com/questions/447898/what-is-object-serialization/…