Reputation: 787
I need some code that could get an InputStream
from a resource stored in some path into a jar file, this is the test code:
String res =File.separatorChar+ "folder"+File.separatorChar+"file.txt";
InputStream is = ReadRes.class.getResourceAsStream(res);
System.out.println(is);
Into my jar I have the directory folder/file.txt, in linux it works but on Windows I get a null value for is
. What should I do?
Upvotes: 2
Views: 350
Reputation: 168845
Always use /
when fetching the resource.
The resource is not a File
, and the path is represented by an URL
which always has forward slashes.
Upvotes: 4