Java 尼奥。空路径

标签 java nio

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

相关文章:

java - 在增强型 for 循环中重复迭代

java - 异常 java.net.SocketException : Connection reset

linux - Netty 的零拷贝和 OS 级别的零拷贝有区别吗?

java - 使用 java NIO 选择器发送文件

java - 如何使用 NIO 从 gzip 文本文件中逐行读取文本数据?

关于线程使用的 Java RMI 规范 : "..may or may not execute in a separate thread"

java - 当底层数据库发生更改时通知应用程序(C++ 或 Java)的最佳方式是什么?

java - 在 IntelliJ 中创建新包

java - java中nio和协程是什么关系?

java - ByteBuffer - CompareTo 方法可能会出现分歧