为了账号安全,请及时绑定邮箱和手机立即绑定

我们可以访问哪些其他位置,例如 Java 中的“user.dir”?

我们可以访问哪些其他位置,例如 Java 中的“user.dir”?

哈士奇WWW 2022-06-08 17:10:24
当我运行时:public static void main(String[] args) {        System.out.println(System.getProperty("user.dir"));    }它提供了我的项目的根位置。同样,如果我指定${project.build.outputDirectory}它会给我位置,/project_root/target但是当我尝试在 main 方法中访问它时它会失败(给出null)。需要一些官方文档,其中此类目录的列表是列表,可以通过pom.xml和 viamain方法以编程方式访问。
查看完整描述

2 回答

?
米脂

TA贡献1836条经验 获得超3个赞

我们可以在您的项目中使用许多系统属性。有些列在官方文档中。休息一下,你可以得到一个小片段。


System.getProperties().entrySet().forEach(e -> {

        System.out.println(e.getKey() + " : " + e.getValue());

    });


查看完整回答
反对 回复 2022-06-08
?
子衿沉夜

TA贡献1828条经验 获得超3个赞

您可以使用 FileHandler


"%t" 系统临时目录 "%h" "user.home" 系统属性的值


https://kodejava.org/how-do-i-get-operating-system-temporary-directory-folder/


 public class TempDirExample {

     public static void main(String[] args) {

         // This is the property name for accessing OS temporary directory

         // or folder.

         String property = "java.io.tmpdir";


         // Get the temporary directory and print it.

         String tempDir = System.getProperty(property);

         System.out.println("OS temporary directory is " + tempDir);

     }

 }

或者您可以通过属性文件传入目录。


查看完整回答
反对 回复 2022-06-08
  • 2 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号