Can someone explain why Java does not find resource if using File.separator
in the String for search path in getResourceAsStream(String name)
? I have this code:
private final String RESOURCE_PATH = File.separator + "dir" + File.separator;
private final String SAME_PATH_HARDCODED = "/dir/";
public void findResource(String fileName) {
InputStream file1 = ThisClass.class
.getResourceAsStream(RESOURCE_PATH + fileName); // returns null
InputStream file2 = ThisClass.class
.getResourceAsStream(SAME_PATH_HARDCODED + fileName); // returns file
}
I have found out, that File.separator
used Backslashes instead of Slashes. But I hoped that File.separator is more flexible. In this case, it isnt. And I want to know, why. Thanks alot.