谁能告诉我 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/