Reputation: 2790
I try to read files from the resources folder. The problem is, that the File.separator
turns into a "%"
on Windows.
String inputFilesFolder = "input_files" + File.separator;
File file = new File(classLoader.getResource(inputFilesFolder + "filename").getFile());
The inputFilesFolder
is still fine (input_files/
), but after creating the file file.getPath()
becomes D:\blabla\input_files%filename
.
Then I try to read the file, but I get a FileNotFoundException (big surprise). What's wrong here?
Upvotes: 1
Views: 2337
Reputation: 1134
File.separator is a file system thing. When you're using classLoader.getResource() always use forward slash as the name of a resource is a '/'-separated path name.
Upvotes: 5
Reputation:
How about
String inputFilesFolder = "input_files" + File.separator;
File file = new File(classLoader.getResource(inputFilesFolder + filename).toString());
Upvotes: 0
Reputation: 42020
Try this:
File file = new File(classLoader.getResource(inputFilesFolder + filename).toURI());
Upvotes: 2