将socresres保存到highscore.sav文件,它在桌面上工作正常,但在android上不起作用。为什么?它可以在桌面上正常工作,但不适用于android。为什么?
String fileName = "highScores.sav";
file = new File(fileName);
public static void save(){
try{
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(gd);
out.close();
}
catch(Exception e){
e.printStackTrace();
System.out.println(e);
Gdx.app.exit();
}
}
public static void load(){
try{
if(!saveFileExists()){
init();
return;
}
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
gd = (GameData) in.readObject();
in.close();
}
catch(Exception e){
e.printStackTrace();
System.out.println(e);
Gdx.app.exit();
}
}
遇到错误:java.io.FileNotFoundException:/highScores.sav:打开失败:EROFS(只读文件系统)
是你会说当你这样做创建你的文件吗? – njzk2
你的问题是什么? – ElectronicGeek
请发布堆栈跟踪。很难弄清楚其他情况会发生什么。 – Shlublu