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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:31:56+00:00 2026-05-31T20:31:56+00:00

I have a file holding default information that I use to load the textFields

  • 0

I have a file holding default information that I use to load the textFields of my application. I looked up how to get this built into my jar file when I build and I was told to put it in the source packages and it would be brought along, so I have done that.

File Structure:

Project
   -Source Packages
       -src
           ~Java Classes
       -defaultFiles
           ~Defaults.txt

The code I am trying to use is this:

BufferedReader in;
try {
    URL resourceURL = FuelProperties.class.getResource("/defaultFiles/Defaults.txt");
    in = new BufferedReader(new FileReader(resourceURL.getPath()));
}

And this works perfectly when I run it through NetBeans but when I build the project and try to run it from the jar file it is not grabbing the file.

I have verified that the default file is being built and exists in the same file structure shown above.

If you can help me out with this I would be extremely grateful as I have no idea what is keeping this from working. Thanks.

  • 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-31T20:31:57+00:00Added an answer on May 31, 2026 at 8:31 pm

    I found the answer after searching through a couple dozen questions. It turns out that you can only get a InputStream of the data within a file within your JAR not a File object like I was attempting to do.
    (If you want the File object you just have to extract the files from the JAR in your program and then you have access to it.)

    So the code that got my problem to work was simply replacing this:

    URL resourceURL = FuelProperties.class.getResource("/defaultFiles/Defaults.txt");
    in = new BufferedReader(new FileReader(resourceURL.getPath()));
    

    With this:

    in = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/defaultFiles/Defaults.txt")));
    

    And now it is working both inside NetBeans and in the Built JAR file.

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

Sidebar

Related Questions

In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
So, I often have to load data into holding tables to run some data
I have a variable in code that can have file path or url as
I have a file that I want to include in Python but the included
I have a file which is an XML representation of some data that is
I have a winforms app that uses a strongly typed custom DataSet for holding
Alright, currently I have my SWF hitting a php file that will go and
I have a file holding some of the variables of a class, and each
I'm trying to read a text file into R so I can use the
I have a GUI program that, in this example, downloads an exe using wget

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.