我是靠谱客的博主 顺利大山,这篇文章主要介绍java 获取tomcat的相对路径_java 读取相对路径 (resin / tomcat),现在分享给大家,希望可以做个参考。

//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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部