About how the java class in the web project obtains the files under the webapp path
The cheap jfV8 | Browsing 979 times
Published on 2016-11-04 21:55 Best answer
Step 1: First get the classpath path
1
String classpath = this.getClass().getResource("/").getPath() .replaceFirst("/", "");
This way you can get the classpath path, similar to:
F:/projects/JavaStudyParent/study-springmvc-junit-test/target/springmvc-junit-test/WEB-INF/classes/
Then intercept WEB-INF/classes to get the WebAPP directory:
1
String webappRoot = classpath.replaceAll("WEB-INF/classes/", "");
The result is:
F:/projects/JavaStudyParent/study- springmvc-junit-test/target/springmvc-junit-test/
You can get all the files in this folder through this path
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326269651&siteId=291194637
Recommended
Ranking