Assuming the following resources are in the class path:
/res/image/logo.png
/res/image/splash.png
Then you can get InputStreamfor logo.png using:
SomeClass.class.getResourceAsStream("/res/image/logo.png");
If you request a resource that does not exist, getResourceAsStream()returns null.
However, if you request a resource that is truly a directory, you will not get null or exception: you really get java.io.ByteArrayInputStream. By dropping bytes from this stream, it appears to be a list of resources in this directory (one per line).
So:
SomeClass.class.getResourceAsStream("/res/image");
Gives a ByteArrayInputStream, which when dropped contains:
logo.png
splash.png
, , getResourceAsStream(), ? - , , ? ( getResource() - , ?)
UPDATE:
getResource() URL- "", , , ( /java/util/List.class). :
jar:file:/C:/projects/<my_proj>/env/jdk/jre/lib/rt.jar!/java/util/List.class
/java/util :
null
, null ( , , , ) , "" , URL- "file:". , File.isDirectory(), .
, . , !; -)