Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

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
 hard-code
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:
your_login/library/Book.class
your_login/library/Employee.class
...
config/library.properties
config/employees.txt
config/books.txt
images/CheckOut.gif
images/CheckIn.gif

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

thanks,


SOLUTION
Avatar of DidierD
DidierD
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If your question is how to format your properties file, then the following is the format:

    [key]=[value]

Here is an example;

   myKey=myValue

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.
Avatar of Mick Barry
Properties props = new Properties();
props.load(this.getClass().getResourceAsStream("/config/library.properties"));

And your properties file should be in the format:

name1=valu1
name2=value2
Avatar of dkim18
dkim18

ASKER

I did the following, but I got FileNotFoundExcetion error.

In my readEmployeeFile() fuction:

Properties props = new Properties();
props.load(this.getClass().getResourceAsStream("/config/library.properties"));
String bookResource = props.getProperty("books");

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

and inside of library.properties:

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

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
InputStreamReader(this.getClass().getResourceAsStream("/config/books.txt")))

but instead read them from the library.properties

What am I doing wrong?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkim18

ASKER

books=/config/books.txt
employees=/config/employees.txt

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