获取项目根目录

来源:互联网 发布:旁氏米粹怎么样知乎 编辑:程序博客网 时间:2024/06/07 06:12
public static String getRootPath(){String rootPath = new BaseUtil().getClass().getResource("/").toString().replace("file:/", "").replace("WEB-INF/classes/", "");//获得系统属性Properties prop = System.getProperties();String osName = prop.getProperty("os.name");if(!osName.startsWith("win")&&!osName.startsWith("Win")){rootPath = "/"+rootPath;  //好像这句话是考虑linux系统,具体不了解,囧……}return rootPath;}