您的位置:首页 > 移动开发 > Objective-C

[Java] IO-05 ObjectIO (java 对象序列化)

2013-12-07 14:37 465 查看
import java.io.*;

public class TestObjectIO {
public static void main(String args[]) throws Exception {
T t = new T();
t.k = 8;
FileOutputStream fos = new FileOutputStream(
"d:/share/java/testobjectio.dat");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(t);
oos.flush();
oos.close();

FileInputStream fis = new FileInputStream(
"d:/share/java/testobjectio.dat");
ObjectInputStream ois = new ObjectInputStream(fis);
T tReaded = (T) ois.readObject();
System.out.println(tReaded.i + " " + tReaded.j + " " + tReaded.d + " "
+ tReaded.k);

}
}

class T implements Serializable {
int i = 10;
int j = 9;
double d = 2.3;
transient int k = 15;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: