• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problem while using properties file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have created servlet that will be automatically when application is started.

when i am specifying

Properties prop = new Properties();
prop.load(new FileInputStream("time.properties"));


even if i have placed .java file and .properties file in same folder , it is given "FileNotFoundException".

i am using Netbeans as an IDE .

can anyone tell me why that Exception ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use ServletContext#getResourceAsStream to read resource files from your application. Check the API to see how to use it. I think that it should be better not to put your properties file with servlets.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Paresh Joshi:

even if i have placed .java file and .properties file in same folder , it is given "FileNotFoundException".

i am using Netbeans as an IDE .



Probably, you might have put your .properties file in the same location as that of .java/.class files. But it should be available in the classpath meaning where the classes are found.

In case of your java or class files under a specific package name say "com.mytest.servlets", you would have have your .java files under "com/mytest/servlets" folder.

For the .properties file, you are supposed to put the .properties in the "classes" direcly [which is present inside your "build" directory in case of NetBeans] and NOT inside "com/mytest/servlets" as that of your .java files.
[ August 14, 2007: Message edited by: Raghavan Muthu ]
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also to know more about "finding class files", please have a look at here.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should help you.
Jaikiran's Blog
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using getResourceAsStream, you can put the file anywhere within your web application that you like.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:
This should help you.
Jaikiran's Blog



The url looks cool. Thanks Rahul.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Raghavan Muthu:


The url looks cool.



Its from the blog of one of the bartenders of Javaranch[Jaikiran Pai].
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:


Its from the blog of one of the bartenders of Javaranch[Jaikiran Pai].



Yeah i am aware of it Rahul!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!