Wednesday, April 8, 2015

Caused by: java.io.FileNotFoundException: class path resource [repository/naver/keyword/keyword_map.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/xxx.jar!/xxx.txt

When you try to access a file in a .jar file as follows:

String resourceLocation = "classpath:xxx.txt";
File file = ResourceUtils.getFile(resourceLocation);

you will encounter the following exception:

Caused by: java.io.FileNotFoundException: class path resource [repository/naver/keyword/keyword_map.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/xxx.jar!/xxx.txt        at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:212)

You can use the following code instead:

String resourceLocation = "/xxx.txt";
InputStream is = getClass().getResourceAsStream(resourceLocation);

No comments:

Post a Comment