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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:18:31+00:00 2026-05-31T17:18:31+00:00

I am attempting to create a simple program that will keep a text log

  • 0

I am attempting to create a simple program that will keep a text log of collected data. To set this up, I have the following code run at the start of the program (to set up the log file, and the tools to use it):

File logFile = new File("logs/logFile.txt");
FileWriter fw;
FileReader fr;
BufferedWriter writer;
BufferedReader reader;

public void someMethod(){
    System.out.println(logFile.getAbsolutePath());
    try{
        logFile.createNewFile();
    }catch(Exception e){
        System.err.println("WARNING: CANNOT CREATE FILE");
    }
    try{
        fw = new FileWriter("plugins/Stalker/log.txt");
        fr = new FileReader("plugins/Stalker/log.txt");
        writer = new BufferedWriter(fw);
        reader = new BufferedReader(fr);
    } catch(Exception e){
        System.err.println("ERROR: CANNOT READ OR WRITE TO LOG FILE");
    }
}

When I run this, I hit both exceptions. It does not create either the file, or the folder (logs) at the path given in the first println. The path is as I expect it to be, and I SHOULD have write permissions for that directory (I know for a fact that other programs regularly write logs and such to a parent directory)… I’ve worked with files a little bit before, but it has been a bit, and I am at a complete loss here.

What sort of problem(s) might I be running into? What attempts at fixing this would you suggest?

  • 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-31T17:18:32+00:00Added an answer on May 31, 2026 at 5:18 pm

    When you are working with folders, you have to make sure that the folder exists.

    For that you have to write a condition before logFile.createNewFile(); to check whether the folder exists because createNewFild will not create folders.

    You have to modify the program little bit like this.

    File logFileFolder = new File("logs");
    File stalkerFolder = new File("plugins/Stalker");
    File logFile = new File("logs/logFile.txt");
    FileWriter fw;
    FileReader fr;
    BufferedWriter writer;
    BufferedReader reader;
    
    public void someMethod(){
        System.out.println(logFile.getAbsolutePath());
        try{
            if (!logFileFolder.exists()){
                 // Create folder if does not exist
                 logFileFolder.mkdir();
            }
            logFile.createNewFile();
        }catch(Exception e){
            System.err.println("WARNING: CANNOT CREATE FILE");
        }
        try{
            if (!stalkerFolder.exists()){
                 // Create folders if does not exist
                 stalkerFolder.mkdirs();
            }
            fw = new FileWriter("plugins/Stalker/log.txt");
            fr = new FileReader("plugins/Stalker/log.txt");
            writer = new BufferedWriter(fw);
            reader = new BufferedReader(fr);
        } catch(Exception e){
            System.err.println("ERROR: CANNOT READ OR WRITE TO LOG FILE");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create my 1st Simple DLL. I have a class(that's a
I'm attempting to create a java program that will allow me access to an
I am attempting to create a simple app that can send a text message
I am attempting to create a simple application using Eclipse GEF that displays a
I'm attempting to create a simple backbone view that attaches to an <li> element.
I'm attempting to create a Google Plus redirect like this... www.domain.com/+ I have created
i'm attempting to create a table with an incremental ID. This isn't the simple
In the example console app below, you will notice that the program is attempting
I'm attempting to create a simple example that would just alert the first 5
Hopefully this will be one of those simple answers that is so simple they

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.