保存对象到文件中
2015-06-25 04:01
260 查看
public static void writeObjectToFile(Object obj)
{
File file =new File("test.dat");
FileOutputStream out;
try {
out = new FileOutputStream(file);
ObjectOutputStream objOut=new ObjectOutputStream(out);
objOut.writeObject(obj);
objOut.flush();
objOut.close();
System.out.println("write object success!");
} catch (IOException e) {
System.out.println("write object failed");
e.printStackTrace();
}
}
{
File file =new File("test.dat");
FileOutputStream out;
try {
out = new FileOutputStream(file);
ObjectOutputStream objOut=new ObjectOutputStream(out);
objOut.writeObject(obj);
objOut.flush();
objOut.close();
System.out.println("write object success!");
} catch (IOException e) {
System.out.println("write object failed");
e.printStackTrace();
}
}
相关文章推荐
- [AngularJS] Extract predicate methods into filters for ng-if and ng-show
- Codeforces 553B Kyoya and Permutation 排列问题
- Codeforces 554A Kyoya and Photobooks 插入照片
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造
- Codeforces 554B Ohana Cleans Up 扫房间
- CF R309C 554C Kyoya and Colored Balls
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合
- hadoop问题集锦及解决办法
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
- windows下提升效率软件推荐
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
- 不折移动web不腾--开启我的个人Mac之旅
- 基于百度网盘下载安卓官网ndk,adt等方法,不用翻墙即可下载最新版本!
- Windows Phone 十六、HttpClient
- Uncaught ReferenceError: $ is not defined
- redis学习笔记之安装
- redis学习笔记之安装
- maven3 junit4 spring3 jdk8 :junit一直报错,害的我几个星期都是这个错,你妹的!
- 【java基础】——GUI(图形化用户界面
- 常用Android开源框架