将对象以二进制形式序列化为文本

来源:互联网 发布:关于养鱼的软件 编辑:程序博客网 时间:2024/05/02 01:33
public static void main(String[] args) throws IOException{Source source = new Source();source.setAnswer("answer12121222222222");    ObjectOutputStream oos = null;           FileOutputStream fos = null;           try {               fos = new FileOutputStream(new File("E:\\object.txt"));             oos = new ObjectOutputStream(fos);               oos.writeObject(source);                    } catch (Exception e) {               e.printStackTrace();           } finally {               if (oos != null) {                   try {                       oos.close();                   } catch (IOException e1) {                       e1.printStackTrace();                   }               }               if (fos != null) {                   try {                       fos.close();                   } catch (IOException e2) {                       e2.printStackTrace();                   }               }           }   }

0 0
原创粉丝点击