Posted on Leave a comment

Resource file not found

[code language=”java”]
File file = new File(getClass().getResource("resourceFile.txt").getFile());
[/code]

but the file doesn’t exist.

It turned out the problem was due to spaces in my path

I found two solutions:

[code language=”java”]
org.apache.commons.io.FileUtils.toFile(myClass().getResource("resourceFile.txt")‌​);
[/code]

[code language=”java”]
myClass().getResource("resourceFile.txt")‌​.toURI();
[/code]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.