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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:19:22+00:00 2026-06-12T01:19:22+00:00

I am trying to create a block that writes a file when the file

  • 0

I am trying to create a block that writes a file when the file doesn’t exsist, but it has turned into a Catch-22. The file doesn’t exist, so it can’t write the file so it can exsist. Here is my attempt:

if(!FileReadWrite.file2.exists())
        FileReadWrite.fileWrite();

public static File file2 = new File("./settings.txt");

public static void fileWrite()
{
    try
    {
         FileWriter fstream = new FileWriter(file2);
         BufferedWriter out = new BufferedWriter(fstream);
         String c = Byte.toString(Textures.a);
         out.write(c);
         out.close();
     }catch (Exception e)
     {
         System.err.println("Error: " + e.getMessage());
     }
    int ch;
    StringBuffer strContent = new StringBuffer("");
    InputStream fin = null;
    try
    {
        fin = new FileInputStream(file2);
        while ((ch = fin.read()) != -1)
        {
            strContent.append((char) ch);
        }
    fin.close();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
}

I am using Eclipse. The file is in the bin folder, but when I export it to a jar it is outside the jar folder.

Exception in thread "main" java.lang.ExceptionInInitializerError
at srcD.Main.<init>(Main.java:19) //(FileReadWrite.fileWrite())
at srcD.Main.main(Main.java:129) //(Make JFrame)
Caused by: java.lang.NullPointerException
at srcD.FileReadWrite.<clinit>(FileReadWrite.java:7) //(public file...)
... 2 more
  • 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-12T01:19:23+00:00Added an answer on June 12, 2026 at 1:19 am

    I think this ClassLoader.getSystemResource("settings.txt") code returns null and .getFile() gets an NPE


    Answer to comment

    Firstly you should understand that method getSystemResource NOT for outside resources read this
    For load outside resources from jar you have to use full path to resource, full != absolute,
    how to find full path

    start point + path to resource
    

    For example we have next files structure /Users/fakeuser/tetsproject/ – this folder contains your jar and conf folder contains or should contain settings.txt, if you have delivery structure like this your code will be

     public static File file2 = new File("./conf/settings.txt");
    

    And that is all.

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

Sidebar

Related Questions

I am trying to create a function that will block access to some of
I'm trying to create a view that only houses reusable HTML blocks that can
Im trying to create counter that using shared block memory, just look code: $i=0;
I am trying to create a chrome extension that will remove/block/hide a piece of
I trying to create a TFTP server but when it receives a file it
I'm trying to create a parsing system for c#, to block my program from
I am trying to block all default methods except create and update in my
Trying to create a black line in my view to separate text blocks but
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to create a Regex to block all < and > in 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.