• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to use Properties file contents

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the way you pick up the file was mentioned by Joe Ess
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic