给定一个静态类,例如MyStaticClass
,它有两种方法可以将自身保存到文件或从文件中加载,例如:
private static void save() throws IOException {
FileOutputStream fos = new FileOutputStream(new File("myfile.dat"));
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(???);
oos.close();
}
private static void load() throws IOException {
FileInputStream fis = new FileInputStream(new File("myfile.dat"));
ObjectInputStream ois = new ObjectInputStream(fis);
??? = (MyStaticClass) ois.readObject();
ois.close();
}
我应该用什么代替???
通常放置对象实例的位置?
有没有办法将静态类保存到与用于实例的文件不同的文件中?