获取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")));
}
}