• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about getResourceAsStream  RSS feed

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how can I use getResourceAsStream() with absolute path?
thanks
 
Ranch Hand
Posts: 67
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the phrase "absolute path", I take it you mean the absolute class path... I make this assumption because if you were talking about a file path, you would just use FileInputStream or something like that, getResourceAsStream wouldn't be involved, and you'd never have asked the question.

Imagine that you have a folder called "resources" bundled in with your application jar file. Your package hierarchy is organized so that the folder is given under "org/example/graphics". Resources might include PNG files for icon images, custom TrueType fonts, default properties files, etc. In this case, I'll use the example of a .csv file mapping color names like "red" to their RGB values.

Now if you had a class in the package "org.example.graphics", it's pretty straightforward to get the resources because they are in an immediate subfolder. But say your class was in "org.example.somethingElse". One way to get the resource would be through something like


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!