SerializableObj

时间:2022-12-21 21:06:09

package JBJADV003;

import java.io.*;

public class SerializableObj {

/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
ObjectOutputStream oos=null;
try{
//创建ObjectOutputStream输出流
oos=new ObjectOutputStream(new FileOutputStream("c:\\myDoc\\stu.txt"));
Student stu=new Student("安娜",30,"女","123456");
//对象序列化,写入输出流
oos.writeObject(stu);

}catch(IOException ex){
ex.printStackTrace();
}finally{
if(oos!=null){
oos.close();
}
}
}

}

相关文章