System.getProperty("catalina.home")
获取tomcat的绝对路径
获取文件的绝对路径
在windous中拼接路径是" " 而linux系统中路径拼接是" / " 所以为了更好的兼容建议用File.separator
例子如下:
properties文件的路径及内容
java代码
private static String getRestfulAddress() { Properties pps = new Properties(); try { String dir2 = System.getProperty("catalina.home") + File.separator +"lib" + File.separator + "emc" + File.separator + "test.properties"; FileInputStream fs = new FileInputStream(dir2); InputStream in = new BufferedInputStream (fs); pps.load(in); String restfulAddress = pps.getProperty("restfulAddress"); in.close(); return restfulAddress; } catch (Exception e) { e.printStackTrace(); } return null; }