java获取项目路径

获取项目根路径(一)

File files = new File("");
String filePath = files.getCanonicalPath();
System.out.println("filePath: " + filePath);

在项目开发中展示的路径: filePath: /home/idea/project/java_basic
在项目打成jar包中的路径: filePath: /home/idea/project/java_basic/selfimpr-fileupload/target

获取项目根路径(二)

String filePath = System.getProperty("user.dir");
System.out.println("filePath: " + filePath);

在项目开发中展示的路径: filePath: /home/idea/project/java_basic
在项目打成jar包中的路径: filePath: /home/idea/project/java_basic/selfimpr-fileupload/target

参考地址:https://www.jianshu.com/p/1c9714622a4f

 

posted @ 2019-09-02 15:16  BrokenColor  阅读(251)  评论(0编辑  收藏  举报