0

I have a little problem. Hopefully you can help me.

I have to keep the scores of a game in a txt file. At the end of the game, I give it a name (no matter what). first i have to write that name to a txt file with the related score. Now my question is how to write something to a file in the Assets folder. Then I have to show that scores in a text view.

2 Answers2

2

You cannot write to the assets folder (see this answer). While you still can write the score to a file (see this answer) I would suggest that you instead write the data pertaining to each game to a database. Database support in Android is great and this would allow for a central store for all the data of all your games. This would make it easier to handle, compare and etc.

Community
  • 1
  • 1
Mafro34
  • 510
  • 8
  • 20
0

I think this can solve your problem

File f = new File(Environment.getExternalStorageDirectory(), "ScoreDetails.txt");
        try {
            StringBuilder scoreDetails = new StringBuilder();
            scoreDetails.append("Score - A");
            scoreDetails.append(" \nScore - B");
            PrintWriter pw = new PrintWriter(f);
            pw.append(scoreDetails.toString());
            pw.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Any confusion.Please let me know

Sourabh s
  • 206
  • 1
  • 7
  • so the PrintWriter includes all the scores? If I want show all the scores in a Textview (label), is that possible to just write s.settext(pw)? I think I am wrong – user3515866 Apr 10 '14 at 16:21