aspose file tools*
The moose likes Servlets and the fly likes Problem while using properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem while using properties file" Watch "Problem while using properties file" New topic
Author

Problem while using properties file

Paresh Joshi
Greenhorn

Joined: Jul 19, 2007
Posts: 5
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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 ]

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

Also to know more about "finding class files", please have a look at here.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
This should help you.
Jaikiran's Blog


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're using getResourceAsStream, you can put the file anywhere within your web application that you like.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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


The url looks cool. Thanks Rahul.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Apr 20, 2006
Posts: 3344

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.
 
subject: Problem while using properties file