首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >退出后保存Jcodemodel对象

退出后保存Jcodemodel对象
EN

Stack Overflow用户
提问于 2014-01-05 14:22:18
回答 1查看 156关注 0票数 0

我对JCodeModel (太阳)有个问题。我的程序每天都在运行,我希望在当前运行之前创建的类中添加一些函数。

JcodeModel支持这个吗?如果没有,可以选择将JCodemodel对象保存在外部文件中,加载以前的JcodeModel,然后添加新函数?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2014-01-06 10:16:25

您可以使用ObjectOutputStream将实例保存到文件中,然后用ObjectInputStream读取并安装它。只要您控制系统,并确保版本不会在一夜之间更改,这应该是安全的(尽管不寻常)。

本教程演示了如何使用它:

代码语言:javascript
复制
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();
  }
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20934652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档