小编asi*_*am9的帖子

如何使用java从linux环境中获取tomcat中当前目录的相对路径

我想用来从我的Web应用程序的外面读取属性文件.我在windows环境中的tomcat中部署了一个war文件,我可以使用以下代码从我的Web应用程序外部读取属性文件.

//(Method 1.)
String filePath = 
new java.io.File( ".").getCanonicalPath()+"/webapps/strsproperties/strs.properties";
// or  
//(Method 2.)
String filePath = new File(System.getProperty("catalina.base"))+ "/webapps/strsproperties/strs.properties";

InputStream inputStream = null;
inputStream = new FileInputStream(filePath);
properties.load(inputStream);
String application = properties.getProperty("applications");
Run Code Online (Sandbox Code Playgroud)

在上面两种情况下,我都可以在windows中读取filePath.

问题是我无法使用第一种方法(相对路径)进程在Linux中读取filePath.

有没有办法在Linux env中使用tomcat中的相对路径读取文件?

java linux tomcat path relative-path

7
推荐指数
1
解决办法
4万
查看次数

标签 统计

java ×1

linux ×1

path ×1

relative-path ×1

tomcat ×1