• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

resource file path

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble with getResourceAsStream. It seems inconstant (i.e. sometimes is seems to work but that may be an Eclipse thing that is unavailable with a standalone app) but essentially it is returning a null which I presume means it did not find the file. What is not clear is how to properly set the file path. The file I'm after in the jar is in a folder named resource. Thus I set the file to 'resource/run.properties'. As a *NIX admin that makes sense since it is relative to the current directory (i.e. the directory containing main). However, I have seen examples that use and absolute path ('/resource/run.properties') which implies to me it will look for an external file. So the question is, what is the proper path for my file as a parameter to getResourceAsStream? TIA.

P.S. Lest someone ask, the file does exist as I have verified it within the jar file.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getResource looks relative to the classpath, not the file system. I always have to go back and read closely, and the method exists in a couple of different places that refer to each other, so it takes some searching, but I think that a leading / means relative to the root of the classpath and no leading / means relative to the same subtree in the classpath as the current class. Or something like that.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic