文章标题

来源:互联网 发布:windows update有用吗 编辑:程序博客网 时间:2024/06/06 19:12
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/io/testobjectio.dat" );          ObjectOutputStream oos = new ObjectOutputStream(fos);          oos.writeObject(t);          oos.flush();          oos.close();          FileInputStream fis = new FileInputStream("d:/share/java/io/testobjectio.dat" );          ObjectInputStream ois = new ObjectInputStream(fis);          T tReaded = (T)ois.readObject();   //读出来是object类型的,强制转换成T类型          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;     int k = 15;}
0 0
原创粉丝点击