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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:05:57+00:00 2026-06-12T21:05:57+00:00

Here is my directory structure XYZProject build dist nbproject src I am working on

  • 0

Here is my directory structure
XYZProject

  • build
  • dist
  • nbproject
  • src

I am working on netbeans.
Now I have a file called ABC.txt
I want to pack this in the jar file.
Now I did the following : made a new folder called Resources under source packages and put the file ABC.txt in that.

XYZProject

-- src  
  |
  -- Resources  
     |
     -- ABC.txt

Now I want to access this file independent of the file location. So I followed some tutorials and did this,

URL url = XYZProject.class.getClassLoader().getResource("Resources/ABC.txt");
String urlStr = urlStr.getFile().replaceAll("%20", " ");
System.out.println(urlStr);
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader(urlStr)); .....
} catch (FileNotFoundException e) {...}

Now this works when I am running the code through netbeans i.e F6 and tada WORKS!!!
But when try to run the jar, it cannot locate the file. It throws FileNotFoundException
How do I access a text file inside a jar running it via netbeans and via java -jar ?
Also I have no idea why there’s a %20 instead of space in the url that I get.

Output running VIA NB

/D:/.../.../.../.../XYZProject/build/classes/Resources/ABC.txt  

Output running VIA java -jar

file:/D:/.../.../.../.../XYZProject/dist/XYZProject.jar!/Resources/ABC.txt
  • 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-12T21:05:59+00:00Added an answer on June 12, 2026 at 9:05 pm

    A resource in a Jar is not a File. It must be accessed by URL or InputStream.

    I would probably use URL -> InputStream -> InputStreamReader -> BufferedReader (from memory, not tested).

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

Sidebar

Related Questions

I have a very simple directory structure: Project Project/src Project/build Source files are in
I have a directory structure & build.xml like this /path-to-project/src/prj1 /path-to-project/src/prj2 /path-to-project/tests /path-to-project/tests/build.xml I
Update : Here is the project. I have the following directory structure: RMI |
I have the following directory structure (root) / | \ bin resources src |
Here is my directory structure: /features/ninja.feature /features/step_definitions/ninja_steps.rb /src/ninja.rb When I run cucumber in the
I'm having trouble adding Facebook Connect to my iPhone Project. Here's the directory structure:
Updated Problem solved, I have some design problem here. The directory looks like that:
This is my directory structure on my Android sdcard sdcard/alQuranData/Reader1/Surah Here is my code
here is the structure of my project. proj ---src ----main ----java ----Main.java ----resources ----res.txt
I have a directory structure with the following on localhost: http://localhost/testing/ A directory structure

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.