首先得到webRoot 的路径:
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
if (classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
}
java.net.URL url = classLoader.getResource("");
String classPath = url.getPath() + "/";//classPath所在的路径
File rootFile = new File(classPath);
String webInfoPath = rootFile.getParent() + "/"; //webInfo所在的路径
File webInfoDir = new File(webInfoPath);
String webRootPATH = webInfoDir.getParent() + "/"; //webroot所在的路径
其次直接引用所需文件的路径。