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

file property problem II

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Why is that when I code:
InputStream is = MyClass.class.getClassLoader().getResourceAsStream("my.properties");
This returns null when my application is runnign as a NT service? Is there another way of getting the path to MyClass?
Thanks in advance!
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you putting the file "my.properties"?
Your code will look in the current directory, which I guess in NT is System32. Try fully qualifying your filename, or use getSystemResourceAsStream()
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code posted will not necessarially look in the current directory. It will look at the same ClassLoader that loaded MyClass. So my.properties should be in the same location (classpath entry) as MyClass.
For example, if MyClass is com.foo.MyClass and is in mystuff.jar then the my.properties file should be in mystuff.jar also.
If MyClass is in a directory like /home/devel/classes/com/foo/MyClass.class, then my.properties should be at /home/devel/classes/my.properties.
If you put them in the same place, then this will always work - if the ClassLoader can load MyClass it should also then find my.properties.
 
reply
    Bookmark Topic Watch Topic
  • New Topic