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 4601570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:50:42+00:00 2026-05-21T23:50:42+00:00

After weeks of not programming I’ve decided to finish my application. Last time I

  • 0

After weeks of not programming I’ve decided to finish my application. Last time I was not able to do the file writing and reading and now I want to do it. I could perhaps use databases but this seems a lot easier.
I have found this page from where I copy-pasted the code. At least now I am able to check the content of the file on my phone (I am not using any virtual SD cards for the time being, but it would definitely accelerate the testing).
Problem is with this code that every time I write the file, close my app and then reopen it and write the file again, the content of the file is reset.

File root = Environment.getExternalStorageDirectory();
File file = new File(root, "tomato50.txt");
if (assignArr.size() > 0) {
    try {
        if (root.canWrite()) {
            FileWriter filewriter = new FileWriter(file);
            BufferedWriter out = new BufferedWriter(filewriter);
            for (int i = 0; i < assignArr.size(); i++) {
                out.write(assignArr.get(i) + "\n");
                Toast.makeText(MainActivity.this,
                        "out: " + assignArr.get(i), Toast.LENGTH_LONG)
                        .show();
            }
            out.close();
        }
    } catch (IOException e) {
        Log.e("TAG", "Could not write file " + e.getMessage());
    }
}

E.g.

  1. I put one item into assignArr.
  2. The item is written into the file.
  3. I close the app. AssignArr gets empty as it is a variable.
  4. I open the app.
  5. I put an item into assignArr.
  6. I close the app. AssignArr gets empty as it is a variable.
  7. I open the file which shows only the last item.
  • 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-05-21T23:50:43+00:00Added an answer on May 21, 2026 at 11:50 pm

    Use FileWriter filewriter = new FileWriter(file,true); to append data to the existing file.

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

Sidebar

Related Questions

After a couple of weeks reading on this forum I thought it was time
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been
Long time reader, first time poster asks: After many weeks of google and forum
I am stuck with asp.net post issue with last 2 weeks. Scenario: My application
after weeks of having this issue I finally decided to ask for a solution
Sorry for my inpatience but after weeks staying up late and just having put
I'm using Eclipse Galileo (v3.51). All of a sudden, after weeks of it starting
After few weeks break, I'm trying to expand and extend my knowlege of templates
I want to find a date after a give weeks(months). For example, I want
After only a few weeks of working with Drupal I've come up with a

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.