Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFound exception

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my class




my properties file also in package called my.
but it gives this error

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aruna,
Its should be absolute path of the properties file.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aruna,
Its should be absolute path of the properties file.


True, but not very practical, is it?

The path used by the FileInputStream constructor is relative to the current working directory of the JVM; it has nothing to do with the package structure. If you want paths relative to your class files, use Class.getResource() to open the file instead.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


True, but not very practical, is it?


Yup ,especially when the application is to shipped to different machine. Class.getResourceAsStream or ClassLoader.getResourceAsStream is good candidate then.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me how to use getResource() in this case
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Read this
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I change my code to this .but still error



Error

 
Manhar Puri
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure why you commented out the line
FileInputStream url= this.getClass().getResourceAsStream("properties");


Is there a reason for changing the path from "properties" to "../properties"?

Try the code below:


Also please provide the name of your properties file as well location.

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


FileInputStream url= this.getClass().getResourceAsStream("properties");


ClassLoader does not add any extension !! Provide complete file name with extn if there is any.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic