Java 获取web项目根目录 RootPath

来源:互联网 发布:js 时间间隔秒 编辑:程序博客网 时间:2024/05/21 06:27
public class Path
{
 public static String getRootPath(){
  String path = null;
   try {
      path = Path.class.getResource("/").toURI().getPath();
      path = path.substring(1, path.length()-1);
      String str = "WEB-INF/classes";
      int i = path.indexOf(str);
      if(i > 0){
       path = path.substring(0, i);
      }
   } catch (Exception e) {
      e.printStackTrace();
   }
  return path;
 }
}
0 0
原创粉丝点击