//TODO tomcat的相对路径
/*String path = "../webapps/lbh5/WEB-INF/config.properties";
File file = new File(path);
String absolutePath = file.getAbsolutePath();
System.out.println("absolutePath:"+absolutePath);*/
//TODO resin的相对路径
String path = "webapps/lbh5/WEB-INF/config.properties";
File file = new File(path);
String absolutePath = file.getAbsolutePath();
System.out.println("absolutePath:"+absolutePath);
//测试
String sysPath = System.getProperty("user.dir");
System.out.println("sysPath:"+sysPath);
绝对路径:
//TODO windows 重新封装路径
String path = String.valueOf(CommonVariable.class.getClassLoader().getResource(""));
System.out.println("path:"+path);
path = path.replace('/', '\'); // 将/换成
path = path.replace("file:", ""); //去掉file:
path = path.replace("classes\", ""); //去掉class
path = path.substring(1); //去掉第一个,如 D:JavaWeb...
path += "config.properties";
System.out.println("path22:"+path);
最后
以上就是顺利大山最近收集整理的关于java 获取tomcat的相对路径_java 读取相对路径 (resin / tomcat)的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复