This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to use Properties file contents  RSS feed

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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: 9521
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
And the way you pick up the file was mentioned by Joe Ess
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!