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().getResourc e("/config /library.p roperties" );
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.cl ass
your_login/library/Employe e.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,
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
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().getResourc
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.cl
your_login/library/Employe
...
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Properties props = new Properties();
props.load(this.getClass() .getResour ceAsStream ("/config/ library.pr operties") );
And your properties file should be in the format:
name1=valu1
name2=value2
props.load(this.getClass()
And your properties file should be in the format:
name1=valu1
name2=value2
ASKER
I did the following, but I got FileNotFoundExcetion error.
In my readEmployeeFile() fuction:
Properties props = new Properties();
props.load(this.getClass() .getResour ceAsStream ("/config/ library.pr operties") );
String bookResource = props.getProperty("books") ;
inFile = new BufferedReader(new InputStreamReader(this.get Class().ge tResourceA sStream(bo okResource )));
and inside of library.properties:
books="classes\config\book s.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.get Class().ge tResourceA sStream("/ config/boo ks.txt")))
but instead read them from the library.properties
What am I doing wrong?
In my readEmployeeFile() fuction:
Properties props = new Properties();
props.load(this.getClass()
String bookResource = props.getProperty("books")
inFile = new BufferedReader(new InputStreamReader(this.get
and inside of library.properties:
books="classes\config\book
employees="classes\config\
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.get
but instead read them from the library.properties
What am I doing wrong?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
books=/config/books.txt
employees=/config/employee s.txt
this solved the problem.
Thank you so much...
employees=/config/employee
this solved the problem.
Thank you so much...
[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.