Exception in thread "main" java.io.WriteAbortedException:
writing aborted; java.io.NotSerializableException: java.io.BufferedReaderCaused by: java.io.NotSerializableException: java.io.BufferedReader这个异常指的是什么啊
代码就是从一个序列化的文件中反序列化
编译不通过,什么原因?指点指点public class Test {
public static void main(String[] args) throws Exception {
File f1 = new File("D:" + File.separator + "Person.txt");
FileInputStream input= input = new FileInputStream(f1);
ObjectInputStream ois = new ObjectInputStream(input);
ois.readObject();
ois.close();
}}
writing aborted; java.io.NotSerializableException: java.io.BufferedReaderCaused by: java.io.NotSerializableException: java.io.BufferedReader这个异常指的是什么啊
代码就是从一个序列化的文件中反序列化
编译不通过,什么原因?指点指点public class Test {
public static void main(String[] args) throws Exception {
File f1 = new File("D:" + File.separator + "Person.txt");
FileInputStream input= input = new FileInputStream(f1);
ObjectInputStream ois = new ObjectInputStream(input);
ois.readObject();
ois.close();
}}
@SuppressWarnings("serial")
public class Person implements Serializable {
private String name ;
private int age ;
public Person(String name,int age){
this.name = name ;
this.age = age ;
}
@Override
public String toString() {
return "姓名:" + this.name + ",年龄:" + this.age ;
}
}
package rog.fxb.test;import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class ObjectDemo {
public static void main(String[] args) throws Exception {
/* File file = new File("D:" + File.separator + "person.txtz");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
file));
Person per = new Person("张三", 30);
oos.writeObject(per);
oos.close();*/
File f1 = new File("D:" + File.separator + "Person.txt");
FileInputStream input = new FileInputStream(f1);
ObjectInputStream ois = new ObjectInputStream(input);
Person per = (Person)ois.readObject();
ois.close();
System.out.println(per);
}
}
文件中的内容是用ObjectOutputStream的writerObject(Object obj)方法保存到文件中的啊
我好像是将对象序列化保存到文件中的啊,开始还试了几次的,都可以反序列化,后来不知道怎么不就总是抛异常
我就是把所有的Person对象添加到 集合里面,我序列化的对象就是序列化一个ArrayList的集合,每次都序列化这个集合都是以覆盖的方式序列化的,我这个集合里面添加的Person对象什么的都实现了Serializable 接口