I'm trying to save the player's top score so that It will be available after the process of the game is terminated. It seems like I got my write to work but whenever I try to read the file I get a <code>FileNotFoundException</code>. Wondering if one of you guys can see what I'm doing wrong.
//The method that saves the file.
public void saveGame(int score){
BufferedWriter outputStream;
try{
outputStream = new BufferedWriter(new FileWriter(new
File(getFilesDir()+File.separator+"scores.txt")));
outputStream.write(Integer.toString(score));
outputStream.close();
} catch (Exception e){
Log.d("outputStream Exception", e.getMessage());
}
Log.d("", "saved to file");
}
//The method that reads the file.
public int readScores(){
String read;
StringBuilder builder = new StringBuilder("");
BufferedReader buffread;
try {
buffread = new BufferedReader(new FileReader(new
File(getFilesDir()+File.separator+"scores.txt")));
} catch (FileNotFoundException e1) {
Log.d("here 0", e1.getMessage());
return -1;
}
try {
while ((read = buffread.readLine()) != null)
builder.append(read);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
buffread.close();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("", builder.toString());
return Integer.parseInt(builder.toString());
}