I have tried to list jar folder files using
getClass().getResourceAsStream("/folderName")
it return null
but getClass().getResourceAsStream("folderName/fileName")
not null
what is the difference?
it works in eclipse but not in jar
file
I have tried to list jar folder files using
getClass().getResourceAsStream("/folderName")
it return null
but getClass().getResourceAsStream("folderName/fileName")
not null
what is the difference?
it works in eclipse but not in jar
file
You're telling the Class Loader to locate the file (resource) in "/folderName"
which is the root (absolute). While "folderName"
is the current folder (relative to) your class is located in.
Plus:
getClass().getResourceAsStream()
is using the System Class Loader. Not the class loader that loaded the parent class.
Use Example.class.getResourceAsStream()
and you should be able to access the resources.