Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to package resource files within project
    primarykey
    data
    text
    <p>I'm not sure if I'm doing this correctly. I want to have a folder or package in my Java project that contains a bunch of text files. In code, I want to list all of the files in the folder, and be able to read them. I want these resource files to be part of my project's directory structure (so that they can be version controlled with my source).</p> <p>I have seen the ClassLoader.*resource methods but can't identify a folder in my source directories and list it's contents...</p> <p>BTW I'm using Eclipse. Does anybody know how to do achieve this goal?</p> <p>Thanks</p> <p>==========================================</p> <p>UPDATE: </p> <p>Thanks for the replies! I found that by adding the source folder, I can only access the files inside by name. This doesn't fit my needs however, as the contents of the folder will change, and I want to be able to read all the contents dynamically, without having to change the read logic every time the contents change. I tried creating a File for a regular folder within the source folder and iterating over it's contents. That works as long as run in Eclipse, but as per Edwin's comment, this will not work when I export to a JAR, so I'm back at square one.</p> <p>I'm thinking there MUST be a way to include resource files in my project that I can access programmatically (Android does this and it's based on java right?). So is there another way to create a 'resources' package containing a bunch of files that I can access at runtime without having to update code to look for each file? I really don't want to have to separate this folder from my source and maintain it in a different location as this will complicate deployment... Does anybody have any ideas?</p> <p>Thanks</p> <p>====================================</p> <p>Solution:</p> <p>I just realized that Android inventories it's resource files at compile time in order to make them available at runtime. So this is probably the way to go: I'll just add a step to my Ant script that writes a file (always named the same so i can access it) containing a list of the files in my folder. This way I'll know the names of all my available resource files. Thanks Edwin for your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload