About properties file

Posted on 2003-11-24
Last Modified: 2013-11-23
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
from my classpath /config/ 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/");
to get a URL to the file located at config/
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 file should be?


Question by:dkim18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1

Assisted Solution

DidierD earned 20 total points
ID: 9816284
LVL 14

Expert Comment

by:Tommy Braas
ID: 9816288
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.
LVL 92

Expert Comment

ID: 9816289
Properties props = new Properties();

And your properties file should be in the format:

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9827188
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


I also created solaris system and ftp into my home pc because I was told shouldn’t .txt format. I tried changing 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

What am I doing wrong?
LVL 14

Assisted Solution

by:Tommy Braas
Tommy Braas earned 80 total points
ID: 9827423
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. "
LVL 92

Accepted Solution

objects earned 150 total points
ID: 9827674
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:



Author Comment

ID: 9828127

this solved the problem.
Thank you so much...
LVL 92

Expert Comment

ID: 9828148

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse Java import and method not resolved 4 76
wild fly 8 startup error 2 40
IBM TS2900 (3572) Tape Autoloader Java? 12 59
Firemonkey Queue list 1 28
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question