java ObjectIO测试

package org.lunzi.test.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TestObjectIO {

public static void main(String[] args) throws Exception {
T t = new T();
t.k = 8;
t.d = 1.3;
String path = "e:/org/lunzi/test/io/test.dat";
/*File file = new File(path);
if(!file.exists()){
file.mkdirs();
}*/

FileOutputStream fos = new FileOutputStream(path);
ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(t);
oos.flush();
oos.close();

fos.close();

FileInputStream fis = new FileInputStream(path);
ObjectInputStream ois = new ObjectInputStream(fis);

T td = (T)ois.readObject();

System.out.println(td.d+
":"+td.k);

ois.close();
fis.close();

}

}

class T implements Serializable {
int i = 11;
int j = 8;
double d = 2.3;
transient int k = 15;
}
lunzi   2008-11-08 18:45:37 评论:1   阅读:263   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog