Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while using properties file

 
Paresh Joshi
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 ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 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.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
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: 3381
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.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should help you.
Jaikiran's Blog
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 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: 3381
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: 3381
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic