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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:14:40+00:00 2026-06-14T17:14:40+00:00

this is the code i use when opening the txt file but it overwrites

  • 0

this is the code i use when opening the txt file but it overwrites the data everytime i want to put in more data.

private  Formatter X;
    private File Y = new File("C:\\Users\\user\\workspace\\Property Charge Management System\\users.txt");
    private Scanner Z;
    public  String[][] PCMSarray;
    public boolean OpenFile() {
        try{
            if(Y.exists()==false){
                X = new Formatter("users.txt");
            }
            return true;
        }
        catch(Exception e){
            System.out.println("File has not yet been created.");
            return false;
        }
    }

This is the code i use to write to the file but this works.

public void WriteToFilecmd(){
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter your First name");
        String Fname = input.next();
        System.out.println("Please enter your Last name");
        String Lname = input.next();
        System.out.println("Please enter your Password");
        String Password = input.next();
        System.out.println("Please enter your user ID");
        String ID = input.next();
        System.out.println("Please enter the first address line of your Property");
        String addressln1 = input.next();
        System.out.println("Please enter the second address line of your Property");
        String addressln2 = input.next();
        System.out.println("Please enter the third address line of your Property");
        String addressln3 = input.next();
        System.out.println("Please enter the properties estimated market value");
        String EstimatedPropertyValue = input.next();
        System.out.println("Please enter your tax owed");
        String Taxowed = input.next();
        input.close();

        X.format("%1$20s %2$20s %3$20s %4$20s %5$20s %6$20s %7$20s %8$20s %9$20s \n",Fname,Lname,Password,ID,addressln1,addressln2,addressln3,EstimatedPropertyValue,Taxowed);
    }
  • 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-14T17:14:41+00:00Added an answer on June 14, 2026 at 5:14 pm

    Use a different constructor for the Formatter, one that takes a FileWriter (which is Appendable), and construct the FileWriter so that it appends to the end of the file:

    // the second boolean parameter, true, marks the file for appending
    FileWriter fileWriter = new FileWriter(fileName, true); 
    Formatter formatter = new Formatter(fileWriter);
    

    As an aside, please learn and follow Java naming rules, else your code will not be easily understood by others (namely us!). Variable and method names should begin with lower-case letters.

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

Sidebar

Related Questions

I usually use XCode but was having a problem opening a file with this
Hi I use this code to save an xml file using (IsolatedStorageFile myIsolatedStorage =
I know this code use to work, I must have accidentally changed something when
hello I have this code that use to sort a datatable. Dim sortingIndex As
How could I refactor this code to use only one Dir[ ] call? Dir[
Here is the code I use to define my array, this code is above
I make call from my app with this code (i use webview because after
If I use this code outside of a method or winmain: ostringstream vertexid; vertexid
I need use this code: <%= button_tag :class => btn btn-primary do %> <%=
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,

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.