• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem while using properties file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
The only cure for that is hours of television radiation. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic