io的问题 基于字符流,实现Manger对象的持久化,并测试。

基于字符流,实现Manger对象的持久化,并测试。
qq_摆摊卖忧伤_0
浏览 962回答 1
1回答

hlc157248yx

//  对象序列化后,保存到文件中去String file = "demo/obj.dat";//实例化一个ObjectOutputStream,参数是一个文件字节流FileOutputStreamObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(file));//实例化一个对象Student stu = new Student("10001", "小明", 20);//写入文件oos.writeObject(stu);oos.flush();oos.close();//反序列化String file = "demo/obj.dat";ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));Student stu = (Student)ois.readObject();System.out.println(stu);ois.close();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java