1

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

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
EL missaoui habib
  • 1,075
  • 1
  • 14
  • 24

1 Answers1

0

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.

  • Also if you're obfuscating the JAR you can't use a static path.
John Ceanko
  • 37
  • 1
  • 6