我对JCodeModel (太阳)有个问题。我的程序每天都在运行,我希望在当前运行之前创建的类中添加一些函数。
JcodeModel支持这个吗?如果没有,可以选择将JCodemodel对象保存在外部文件中,加载以前的JcodeModel,然后添加新函数?
谢谢。
发布于 2014-01-06 10:16:25
您可以使用ObjectOutputStream将实例保存到文件中,然后用ObjectInputStream读取并安装它。只要您控制系统,并确保版本不会在一夜之间更改,这应该是安全的(尽管不寻常)。
本教程演示了如何使用它:
import java.io.*;
public class ObjectOutputStreamDemo {
public static void main(String[] args) {
String s = "Hello world!";
int i = 897648764;
try {
// create a new file with an ObjectOutputStream
FileOutputStream out = new FileOutputStream("test.txt");
ObjectOutputStream oout = new ObjectOutputStream(out);
// write something in the file
oout.writeObject(s);
oout.writeObject(i);
// close the stream
oout.close();
// create an ObjectInputStream for the file we created before
ObjectInputStream ois =
new ObjectInputStream(new FileInputStream("test.txt"));
// read and print what we wrote before
System.out.println("" + (String) ois.readObject());
System.out.println("" + ois.readObject());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}https://stackoverflow.com/questions/20934652
复制相似问题