aspose file tools*
The moose likes Java in General and the fly likes How to use Properties file contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use Properties file contents" Watch "How to use Properties file contents" New topic
Author

How to use Properties file contents

Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
Hi,

I had been using the properties file in JSP, JSF it works fine.

I want to implement the same here in the java code. Here i am using a web application where the property file is placed inside a package. I have some details like File Name, File Path, etc..

So, if i try to refer the file with "abc.properties". I get the exception as FileNotFoundException.

How can we refer them inside the project?


Regards,
Hari
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

How are you trying to load the properties file?
Where is the properties file stored?
I usually put properties files at the root of the classpath (the anonymous package), get a InputStream with Class.getResourceAsStream() and pass that to the Properties class.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Yes, it is all about the JRE is unable to find/locate your properties file class.

It is because your CLASSPATH environment variable does NOT have the location to identify it and pick it up!

In case of a web application, it is better to keep it inside the "WEB-INF/classes" directory as this location is by default added into the classpath searched by the web container.

In case of plain Java application, you either add the location of this file to CLASSPATH environment or you place the files in any of the directories present in the CLASSPATH.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

And the way you pick up the file was mentioned by Joe Ess
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Properties file contents