package com.Java;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Objectserial {
public static void main(String[] args) throws Exception{
String file="exer/obj.dat";
// //1:对象序列化
// ObjectOutputStream oos=new ObjectOutputStream(
// new FileOutputStream(file));
// Studentserial stu =new Studentserial("1001","张安",21);
// oos.writeObject(stu);
// oos.flush();
// oos.close();
ObjectInputStream ois=new ObjectInputStream(
new FileInputStream(file));
Studentserial stu =(Studentserial)ois.readObject();
System.out.println(stu);
ois.close();
}
}这一段代码问题错在哪儿额?
我ecplise中新建了exer文件夹
new FileInputStream(file);
如果文件不存在可以自动创建,但如果文件夹不存在它就会报错。
exer这个文件夹要自己创建一下