异常截图
前提:我已经在项目目录下创建好stu.txt和tea.txt文件
出现这个异常不知道怎么处理
InputOutput类代码
package moudle;
import java.io.*;
import java.util.HashMap;
/*
文件操作类
*/
public class InputOutput implements Serializable{
HashMap<Integer,Student> stuMap = null;
HashMap<Integer,Teacher> teaMap = null;
ObjectInputStream teaInput = null;
ObjectInputStream stuInput = null;
File stuFile = null;
File teaFile = null;
String stupath = null;
String teapath = null;
public void ReadByFile() throws IOException, ClassNotFoundException {
try{
stupath = new File("").getCanonicalPath()+"/stu.txt";
teapath = new File("").getCanonicalPath()+"/tea.txt";
}catch (Exception e){
e.printStackTrace();
}
try {
FileInputStream stu = new FileInputStream(stupath);
FileInputStream tea = new FileInputStream(teapath);
stuInput = new ObjectInputStream(stu);
teaInput = new ObjectInputStream(tea);
}catch (FileNotFoundException fileNotFoundException){
fileNotFoundException.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}finally {
if(teaInput != null){
teaMap = (HashMap<Integer,Teacher>)teaInput.readObject();
stuInput.close();
}
if(stuInput != null){
stuMap = (HashMap<Integer,Student>)stuInput.readObject();
teaInput.close();
}
}
}
public void WriteToFile() throws IOException {
ObjectOutputStream stuOut = null;
ObjectOutputStream teaOut = null;
try {
stuMap = TeacherSystem.stuMap;
teaMap = AdminSystem.teaMap;
FileOutputStream stu = new FileOutputStream(stupath);
FileOutputStream tea = new FileOutputStream(teapath);
stuOut = new ObjectOutputStream(stu);
teaOut = new ObjectOutputStream(tea);
}catch (Exception e){
e.printStackTrace();
}finally {
//将map集合里的信息写入文件中
stuOut.writeObject(stuMap);
teaOut.writeObject(teaMap);
//释放资源
stuOut.flush();
stuOut.close();
teaOut.close();
}
}
}