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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:32:24+00:00 2026-05-17T21:32:24+00:00

I am working with Java. I have created one text file. In that text

  • 0

I am working with Java.

I have created one text file. In that text file, I want one value to be stored in the text file from class1. Then I want one more value to be stored in the textfile from class2 on the 2nd line. Then I want one more value to be stored in line 3 of the text file from class 3 , etc. The text file, when retrieved, should look like this:

77 
65 
34

The problem I encounter is that, the text file content gets erased when I move on to the next class. For example, the text file would only show the last data value. And erase the previous ones (in the example above, only 34 would appear that too on the first line, when it should be on the 3rd line).

Some code from class1:

BufferedWriter outputFile0=null;
    try {
        int x = value_MAP();        
        FileWriter fwriter0 =new FileWriter("MAP_allData.txt");
            outputFile0 = new BufferedWriter(fwriter0);
                outputFile0.write(""+x);
                outputFile0.newLine();  
                               } catch( Exception y ) {y.printStackTrace();}

Same code again appears in class2, class3, etc:

BufferedWriter outputFile0=null;
        try {
            int x = value_MAP();        
            FileWriter fwriter0 =new FileWriter("MAP_allData.txt");
                outputFile0 = new BufferedWriter(fwriter0);
                    outputFile0.write(""+x);
                    outputFile0.newLine();  
                                   } catch( Exception y ) {y.printStackTrace();}

So is there a way to tell Java that dont worry about erasing the data, just add data one line after another when traveling from class 1 to class x.

  • 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-17T21:32:24+00:00Added an answer on May 17, 2026 at 9:32 pm

    To appnend and not to erase existing data in a file, you should be using the FileWriter constructor like this..

    FileWriter fwriter0 =new FileWriter("MAP_allData.txt", true);
    

    The second ‘boolean’ argument ‘true’ in the constructor will tell the file writer to append.
    javadoc

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

Sidebar

Related Questions

I have a simple question (working with Java). I have two classes, one represents
I have been working on a Java project for a class for a while
I'm working on a java program, and I have several vectors defined and filled
Does anyone have any experience with doing this? I'm working on a Java decompiler
Would a LINQ for java be a useful tool? I have been working on
This is a nasty one for me... I'm a PHP guy working in Java
I have created a rather complicated piece of (Java) code for a game I
I'm working in Java with XML and I'm wondering; what's the difference between an
I am working in Java on a fairly large project. My question is about
I recently started working in Java and was introduced to the wild and crazy

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.