各位xdm好, 本人,最近刚完成CS61B Proj2 BYog
在去gradescope提交的时候, 在save game 和 loadgame 这个功能这里报错了
这是save 和load 那一块的代码
private void saveGame() {
File f = new File("./Game.ser");
try {
if (!f.exists()) {
f.createNewFile();
}
FileOutputStream fs = new FileOutputStream(f);
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(this);
os.close();
} catch (FileNotFoundException e) {
System.out.println("file not found");
System.exit(0);
} catch (IOException e) {
System.out.println(e);
System.exit(0);
}
}
private static Game getSavedGame() {
File f = new File("./Game.ser");
if (f.exists()) {
try {
System.out.println("Readable: " + f.canRead());
FileInputStream fs = new FileInputStream(f);
ObjectInputStream os = new ObjectInputStream(fs);
return (Game) os.readObject();
} catch (FileNotFoundException e) {
System.out.println("file not found");
System.exit(0);
} catch (IOException e) {
System.out.println(e);
System.exit(0);
} catch (ClassNotFoundException e) {
System.out.println("class not found");
System.exit(0);
}
}
return null;
}
运行这个jar工程的用户没有Game.ser的读取权限
破案了 是我的输出文档格式 不是txt 家人们