Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:58:34+00:00 2026-06-05T13:58:34+00:00

I’m developing a little Game at the Moment (Android-App) and I want to save

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:58:35+00:00Added an answer on June 5, 2026 at 1:58 pm

    plese refe this link to wtire a file

    http://developer.android.com/guide/topics/data/data-storage.html#pref

    Writing to text file in "APPEND mode" in emulator-mode,

    does the FileWriter deletes an existing file and creates a new file with the same name if the filename already exists
    

    yes but consider

    public FileWriter(File file,
                      boolean append)
    append - if true, then bytes will be written to the end of the file rather than the beginning 
    

    it you want to make your file private write in internal storage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
i want to parse a xhtml file and display in UITableView. what is the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.