Below snippet return the resource file path.
public static String resourceFilePath(String resourceFile) {
ClassLoader classLoader = FileUtil.class.getClassLoader();
URL url = classLoader.getResource(resourceFile);
return url.getPath();
}
Find the below class.
FileUtil.java
package com.sample.app.util;
import java.net.URL;
public class FileUtil {
public static String resourceFilePath(String resourceFile) {
ClassLoader classLoader = FileUtil.class.getClassLoader();
URL url = classLoader.getResource(resourceFile);
return url.getPath();
}
}
You may like
Create file parent directories if they are not exist
Get file name from absolute path
Count number of lines in a file
No comments:
Post a Comment