java 反序列化报错 提示:java.io.StreamCorruptedException 异常
publicvoidview(){//TODOAuto-generatedmethodstubSystem.out.println("请输入要操作的文件路径");Scan...
public void view() {
// TODO Auto-generated method stub
System.out.println("请输入要操作的文件路径");
Scanner scan = new Scanner(System.in);
String fileUrl = scan.nextLine();
File file = new File(fileUrl);
impl emp = new impl();
if (file.exists()) {
System.out.println("该文件已经找到");
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
while (ois.readObject() != null) {
ArrayList<impl> arr = (ArrayList<impl>) ois.readObject();
for (int i = 0; i < arr.size(); i++) {
System.out.println(arr.get(i).getName());
System.out.println(arr.get(i).getBirthDate());
System.out.println(arr.get(i).getCreateDate());
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
控制台中:
java.io.StreamCorruptedException
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at neu.impl.view(impl.java:109)
at neu.test.main(test.java:28) 展开
// TODO Auto-generated method stub
System.out.println("请输入要操作的文件路径");
Scanner scan = new Scanner(System.in);
String fileUrl = scan.nextLine();
File file = new File(fileUrl);
impl emp = new impl();
if (file.exists()) {
System.out.println("该文件已经找到");
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
while (ois.readObject() != null) {
ArrayList<impl> arr = (ArrayList<impl>) ois.readObject();
for (int i = 0; i < arr.size(); i++) {
System.out.println(arr.get(i).getName());
System.out.println(arr.get(i).getBirthDate());
System.out.println(arr.get(i).getCreateDate());
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
控制台中:
java.io.StreamCorruptedException
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at neu.impl.view(impl.java:109)
at neu.test.main(test.java:28) 展开
4个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询