java引用webRoot下的文件

来源:互联网 发布:抽数字软件在线 编辑:程序博客网 时间:2024/06/09 20:46

首先得到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所在的路径

其次直接引用所需文件的路径。

0 0