I'm developing a little Game at the Moment (Android-App) and I want to save my Highscores into a .txt-File, because if I would save it just in a list, the list would be empty everytime I start the App new. For java-programs in general this is not a problem for me, because the FileWriter creates a .txt in the program-folder. If I do that in Android, I get (of course) the error, that he couldnt create the file.
So how do I tell the FileWriter where to save the File and where should I save it? Does the FileWriter deletes an existing file and creates a new file with the same name if the filename already exists like the "MODE_PRIVATE"-Mode from the FileOutput?
I know I could use the FileOutput/InputStream to save a file in the internal storage, but the FileOutput just accepts bytes (which is no problem with the .getBytes()-Method), but I cant find a way to transform the bytes back into Strings when I want to read them.
(I apologize for any grammar-mistakes as english is not my native language)
UPDATE:
At first big thanks for the help so far. But i still need some specific help. Thats what i want to do: Everytime my Game is finished, I switch to the Points activity and give him the points reached. In the points-activity I put the points into a List and write this list into a file in the internal storage. In the Highscores-Activity I want to read this file and put the content of the File in a List to print it on the Screen with a ListView. This is the code for writing the File:
ArrayList<Integer> highscoreListe = new ArrayList<Integer>();
punkte = getIntent().getExtras().getInt("Punkte");
public void writeToExternalStoragePublic() throws IOException
{
String filename = "highscores.txt";
FileOutputStream fos= null;
OutputStreamWriter osw = null;
fos= openFileOutput(filename,Context.MODE_PRIVATE);
osw = new OutputStreamWriter(fos);
for(Integer score : highscoreListe)
{
osw.write(score);
osw.append(System.getProperty("line.separator"));
}
osw.close();
fos.close();
}
I read a lot of Questions on stackoverflow about this but I still dont know how to read this file to put for every line in the file a new string or int into a list. I hope you understand what I want to do.