如上代码两个linux下结果:
tomcatPath:/home/app_admin/apache-tomcat-6.0.18/logs
path:/home/app_admin/apache-tomcat-6.0.18/webapps/pathtest/WEB-INF/classes/a.properties
filepath:/home/app_admin/apache-tomcat-6.0.18/logsspeed.txt
tomcatPath:/home/liuhy/apache-tomcat-6.0.29/bin
path:/home/liuhy/apache-tomcat-6.0.29/webapps/pathtest/WEB-INF/classes/a.properties
filepath:/home/liuhy/apache-tomcat-6.0.29/webapps/CDNManageSystem/speed.txt
windows下的结果:
tomcatPath:C:/Tomcat6.0/bin
path:/C:/Tomcat6.0/webapps/pathtest/WEB-INF/classes/a.properties
filepath:C:/Tomcat6.0/webapps/CDNManageSystem/speed.txt
总结下:
user.dir获得的路径:在哪执行的java命令,就是哪。可是第一个系统怎么会在logs下????
下面两个在bin目录下很正常。在logs下,这就有点说不过去了
如果从java类中获得path还是用getResource比较靠谱