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

  • Home
  • SEARCH
  • 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 4007418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:37:48+00:00 2026-05-20T08:37:48+00:00

I am having an annoying problem that I cannot seem to fix. I have

  • 0

I am having an annoying problem that I cannot seem to fix. I have a class named DirFormMgmt which manages two files; directories.txt and formats.txt. The problem is that when I instantiate an instance of this class when the program starts it clears everything that was in the files before it started, so for instance if I open the formats.txt file and type in “.avi” and run the program the text file will become blank. Here is the only code I have running in my class to isolate the issue and I am unsure of why this is happening:

At the top of my class I declare:

File dirFile = new File("directories.txt");
File formatFile = new File("formats.txt");
private BufferedReader dirReader;
private BufferedWriter dirWriter;
private BufferedReader formatReader;
private BufferedWriter formatWriter;

The constructor:

public DirFormMgmt() throws IOException {
     checkFileExistence();
     initReaderWriter();
}

The two methods called by the constructor:

public void checkFileExistence() throws IOException {
     if (!dirFile.exists()) {
         dirFile.createNewFile();
     }
     if (!formatFile.exists()) {
         formatFile.createNewFile();
     }   
}

and:

public void initReaderWriter() throws IOException {
     dirReader = new BufferedReader(new FileReader(dirFile));
     dirWriter = new BufferedWriter(new FileWriter(dirFile));

     formatReader = new BufferedReader(new FileReader(formatFile));
     formatWriter = new BufferedWriter(new FileWriter(formatFile));
}

I checked to see if the createNewFile() methods were being called but they were not, so the problem must be with my initReaderWriter() method, but I am unsure of what is wrong, any help is greatly appreciated!

  • 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-20T08:37:49+00:00Added an answer on May 20, 2026 at 8:37 am

    Use new FileWriter(file, true) to append content to an existing file. Otherwise, the contents will be overwritten.

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

Sidebar

Related Questions

I'm having an annoying problem, that may have a simple answer! I have a
I'm having a annoying problem with a C++ function that I wrote and whose
I've run into a very annoying problem that I'm having an impossible time solving.
I'm having an annoying problem with my iPhone app. Whenever I set the optimization
I'm having to open the firefox error console, which is kind of annoying.
I've been having a problem with a pesky little function in a class in
I'm having an annoying problem trying to get an html page with a google
we've got an almost-finished-ready-to-go magento shop, that has developed an annoying problem. On the
I have an annoying problem with Java’s layout managers. I have the following situation:
Well, sorry about the confusing title but I'm having a slightly annoying problem with

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.