About properties file

I am working on java applet and all .class files, images and text files will be loaded from the
applet archive attribute jar file named your_login.jar. My
program will first load a configuration file named library.properties
from my classpath /config/library.properties. From there my
program will load the employees.txt and books.txt file also in the
config subdirectory - see below jar file content. I am not supposed
employee/book values but instead read them in at runtime using the
following files: employees.txt and books.txt that I should include
in my jar file config directory. I know that I could
use this.getClass().getResource("/config/library.properties");
to get a URL to the file located at config/library.properties
in my jar file. I think I need to use getResourceAsStream to get an InputStream
to that resource.

your_login.jar (library jar file loaded by applet) contains the following:

jar xvf your_login.jar will create relative to the current directory:

My question is how my library.properties file should be?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy BraasCommented:
If your question is how to format your properties file, then the following is the format:


Here is an example;


Don't forget that the same characters that you would escape in s String constant in Java, also needs to be escaped in your properties file.
Mick BarryJava DeveloperCommented:
Properties props = new Properties();

And your properties file should be in the format:

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

dkim18Author Commented:
I did the following, but I got FileNotFoundExcetion error.

In my readEmployeeFile() fuction:

Properties props = new Properties();
String bookResource = props.getProperty("books");

inFile = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(bookResource)));

and inside of library.properties:


I also created library.properties solaris system and ftp into my home pc because I was told library.properties shouldn’t .txt format. I tried changing library.properties executable file too, but wasn’t successful.
In my config dir, books.txt and employees.txt are located, but I shouldn’t hardcode like this:
inFile = new BufferedReader(new

but instead read them from the library.properties

What am I doing wrong?
Tommy BraasCommented:
Try using:

   public URL Class.getResource(String name)

and see what the URL is pointing to by calling either toString() or toExternalForm().

According to the Javadocs on getResource:

"Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class.

This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource. "
Mick BarryJava DeveloperCommented:
WHere exactly are you getting the error, and where are your properties and txt files located?

> books="classes\config\books.txt"
> employees="classes\config\employees.txt"

should perhaps be:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dkim18Author Commented:

this solved the problem.
Thank you so much...
Mick BarryJava DeveloperCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.