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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:33:18+00:00 2026-05-21T17:33:18+00:00

I am trying to access a directory inside my jar file. I want to

  • 0

I am trying to access a directory inside my jar file.
I want to go through every of the files inside the directory itself. I tried, for example, using the following:

URL imagesDirectoryURL=getClass().getClassLoader().getResource("Images");

if(imagesFolderURL!=null)
{
    File imagesDirectory= new File(imagesDirectoryURL.getFile());
}

If I test this applet, it works well. But once I put the contents into the jar, it doesn’t because of several reasons.
If I use this code, the URL always points outside the jar, so I have to put the Images directory there.
But if I use new File(imagesDirectoryURL.toURI());, it doesn’t work inside the jar because I get the error URI not hierarchical. I am sure the directory exists inside the jar.
How am I supposed the get the contents of Images inside the jar?

  • 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-21T17:33:18+00:00Added an answer on May 21, 2026 at 5:33 pm

    Paths within Jars are paths, not actual directories as you can use them on a file system. To get all resources within a particular path of a Jar file:

    • Gain an URL pointing to the Jar.
    • Get an InputStream from the URL.
    • Construct a ZipInputStream from the InputStream.
    • Iterate each ZipEntry, looking for matches to the desired path.

    ..will I still be able to test my Applet when it’s not inside that jar? Or will I have to program two ways to get my Images?

    The ZipInputStream will not work with loose resources in directories on the file system. But then, I would strongly recommend using a build tool such as Ant to build (compile/jar/sign etc.) the applet. It might take an hour or so to write the build script & check it, but thereafter you can build the project by a few keystrokes and a couple of seconds.

    It would be quite annoying if I always have to extract and sign my jar if I want to test my Aplet

    I’m not sure what you mean there. Where does the ‘extract’ come into it? In case I was not clear, a sand-boxed applet can load resources this way, from any Jar that is mentioned in the archive attribute. Another thing you might do, is to separate the resource Jar(s) from the applet Jar. Resources typically change less than code, so your build might be able to take some shortcuts.

    I think I really have to consider putting my Images into a seperate directory outside the jar.

    If you mean on the server, there will be no practical way to get a listing of the image files short of help from the server. E.G. Some servers are insecurely set up to produce an HTML based ‘file list’ for any directory with no default file (such as an index.html).


    I have only got one jar, in which my classes, images and sounds are.

    OK – consider moving the sounds & images into a separate Jar. Or at the very least, put them in the Jar with ‘no compression’. While Zip comression techniques work well with classes, they are less efficient at compressing (otherwise already compressed) media formats.

    I have to sign it because I use the “Preferences” class to save user settings.”

    There are alternatives to the Preferences for applets, such as cookies. In the case of plug-in 2 architecture applet, you can launch the applet (still embedded in the browser) using Java Web Start. JWS offers the PersistenceService. Here is my small demo. of the PersistenceService.

    Speaking of JWS, that brings me to: Are you absolutely certain this game would be better as an applet, rather than an app (e.g. using a JFrame) launched using JWS?

    Applets will give you no end of stress, and JWS has offered the PersistenceService since it was introduced in Java 1.2.

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

Sidebar

Related Questions

I'm trying to access some files stored in the application's documents directory by using
I'm trying to access an XML file within a jar file, from a separate
I'm trying to access a resource from the class path/JAR file as a File
I am trying to access some files in a directory I have under applications
I am trying to access an XML file store in the resources directory. I
I am trying to rewrite all URIs inside directory /docs to /docs/index.php, using apaches
I am trying to access images in the /assets/images directory in my scss file
I'm currently trying to access Active Directory via the dbms_ldap API in Pl/Sql (Oracle).
I'm trying to access a Active Directory from my local webserver. To do this
I am trying to access an image file from the drawable folder; directly in

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.