gpt4 book ai didi

Java 尼奥。空路径

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:07:01 26 4
gpt4 key购买 nike

谁能告诉我 Paths.get("") 指向哪里?

这是代码和输出。

public static void main(String[] args) {
Path path = Paths.get("");
System.out.printf("`%s`%n", path);
System.out.printf("`%s`%n", path.normalize());
System.out.println(Files.exists(path));
System.out.println(Files.isExecutable(path));
}

``
``
true
true

最佳答案

System.out.println(Paths.get("").toAbsolutePath());

/Users/andrew/workspace/scratch

看起来是当前工作目录。在我的机器上,Java 报告它是可执行的,因为目录上的“x”标志对当前用户而言是正确的。

来自javadocs :

This method checks that a file exists and that this Java virtual machine has appropriate privileges to execute the file. The semantics may differ when checking access to a directory. For example, on UNIX systems, checking for execute access checks that the Java virtual machine has permission to search the directory in order to access file or subdirectories.

关于Java 尼奥。空路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40368471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com