java获取项目绝对路径

时间:2022-08-26 15:41:44

java获取项目绝对路径

java获取项目绝对路径

view sourceprint?
01 public static void main(String[] args) {
02     //获取是项目的绝对路径
03     System.out.println(System.getProperty("user.dir"));
04     System.out.println(new File("").getAbsolutePath());
05     //获取到clsspath绝对路径
06     System.out.println(ServerDemo.class.getResource("/"));
07     System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
08     System.out.println(ServerDemo.class.getClassLoader().getResource(""));
09  
10 }