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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:53:51+00:00 2026-05-17T22:53:51+00:00

I know that .jar files are basically archives as well as being applications. What

  • 0

I know that .jar files are basically archives as well as being applications. What I’m asking is how can I store data(actual files not just strings) packed inside my program? I want to do this within my Java code.

The reason for this if your wondering is that I’m producing a server mod of a game. The server starts and creates all the level data and I want to store all these file inside my .jar app.

  • 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-17T22:53:52+00:00Added an answer on May 17, 2026 at 10:53 pm

    Yes you can do this.

    Non-code resources in a JAR file on the classpath can be accessed using Class.getResourceAsStream(String). Applications routinely do this, for example, to embed internationalized messages as resource bundles.

    To get your file into the JAR file (at project build time!), just copy it into the appropriate place in the input directory tree before you run the jar command. Build tools such as Maven, Gradle, etc can automate that for you.


    Is there a way to add files to the archive within the app?

    In theory, your application could store files inside its own JAR file, under certain circumstances:

    • The JAR has to be a file in the local file system; i.e. not a JAR that was fetched from a remote server.
    • The application has to have write access to the JAR file and its parent directory.
    • The application must not need to read back the file it wrote to the JAR in the current classloader; i.e. without exiting and restarting.
    • The JAR must not need to be be signed.

    The procedure would be:

    1. Locate the JAR file and open as a ZIP archive reader.
    2. Create a ZIP archive writer to write a new version of JAR file.
    3. Write the application’s files to the writer.
    4. Write all resources from the ZIP reader to the writer, excluding old versions of the applications files.
    5. Close the reader and writer.
    6. Rename the new version of the JAR to replace the old one.

    The last step might not work if the initial JAR is locked by the JVM / OS. In that case, you need do the renaming in a wrapper script.

    However, I think that most people would agree that this is a BAD IDEA. It is simpler, more robust and more secure to just write the stuff you want to save as regular files in the filesystem.

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

Sidebar

Related Questions

I know that we shouldn't being using the registry to store Application Data anymore,
I have files named xxx.java.i , xxx.java.d , xxx.jar.i . I know that these
I need to store data into files inside .jar file and read it again.
Can anyone recommend me a site that tracks the metadata of Jar files including
Why should I sign my JAR files? I know that I need to sign
I know that I can do something like $int = (int)99; //(int) has a
I know that you can insert multiple rows at once, is there a way
I know that the MsNLB can be configured to user mulitcast with IGMP. However,
Just wondering, if it is generally a good idea to compress jar files that
I'm developing a program on MacOSx that uses third party jar files that all

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.