获取tomcat下路径

import java.io.File;
public class MainTest {
    public static void main(String[] args) {
        //获取是项目的绝对路径
        System.out.println(System.getProperty("user.dir"));
        System.out.println(new File("").getAbsolutePath());
        //获取到clsspath绝对路径
        System.out.println(MainTest.class.getResource("/"));
        System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
        System.out.println(Test.class.getClassLoader().getResource(""));

     System.out.println(System.getProperty("user.dir").replace("bin", "webapps")));
    }
}

 

posted @ 2016-10-18 16:09  豆腐全家  阅读(940)  评论(0编辑  收藏  举报