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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:52:00+00:00 2026-06-17T17:52:00+00:00

Possible Duplicate: How can a Java program use files inside the .jar for read

  • 0

Possible Duplicate:
How can a Java program use files inside the .jar for read and write?

I am in the process of creating a game, and I want it all to run from on runnable jar file, so all of my resources (images and text files) are going to be inside the jar file.

The problem that I’m having with this is that it is extremely difficult to deal with files inside the jar.

I am using eclipse, which can sometimes play tricks on you because it will find the files if you run it from eclipse, but if you export it won’t.

I just want to know basically the proper way to dew a few things:

  1. I need to be able to load images (which I have working, somehow. I sort of tinkered with it and did it on accident, so I have no clue how it works)
  2. I need to be able to read from text files (I have this working too, again, by accident and hours of guessing.)
  3. I need to be able to write to text files that exist and and are in the jar. This is what is making me think I’m doing it all wrong. All I want to do is be able to save certain settings so they work on the next load, and I have no clue how to write to the file.

In eclipse (Indigo) I made a folder names “resources” and marked it as a source folder. I put all of my images and text files in there.
I read in images like this:

public static Image ammo = new ImageIcon(TankMazeGame.class.getResource("ammo.png")).getImage();

I read text files like this:

InputStream is = TankMazeRunner.class.getClassLoader().getResourceAsStream("Settings.txt");
Scanner settingsReader = new Scanner(new InputStreamReader(is));

I am writing to my settings file like this, but it isn’t really working, so that’s what I need help with.

File settingsFile = new File(DisplayMenu.class.getClassLoader().getResource("Settings.txt").getFile());
try {
    OutputStream os = new FileOutputStream(settingsFile, true);
    PrintWriter pw = new PrintWriter(os, true);
    pw.write("SIZE: " + TankMazeRunner.WIDTH + "\n");
    os.flush();
    pw.close(); 
} catch (Exception e2) {
    System.out.println("Error");
}

As you can probably tell from my code, I’m lost.

  • 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-17T17:52:02+00:00Added an answer on June 17, 2026 at 5:52 pm

    How about you write settings to a well known location outside of the JAR?

    As alternatives for saving settings, consider one of these approaches:

    • java.util.prefs.Preferences, mentioned here.

    • JWS PersistenceService, described here.

    • Cookies, discussed in Accessing Cookies.

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

Sidebar

Related Questions

Possible Duplicate: How can a Java program use files inside the .jar for read
Possible Duplicate: How do I compare strings in Java? Why can't my program use
Possible Duplicate: Can we use any other TAG inside <ul> along with <li>? Or
Possible Duplicate: How can I convert my Java program to an .exe file? I
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: Execute another jar in a java program I am making a program
Possible Duplicate: Java 1.6: Creating an array of List<T> How can I initialize this
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: How can I convert my Java program to an .exe file? Is
Possible Duplicate: How can I communicate between PHP and a Java program? I'm currently

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.