来自File
类JavaDoc:
An abstract representation of file and directory pathnames.
User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames.
为什么方法 .isAbsolute()
平台相关? (在 Win 和 Linux 上为 /tmp
返回不同的结果)并且不检查文件是绝对的还是 Linux 或 Windows? File
类如何猜测我试图通过代码中的 File
表示哪个平台的文件?我不一定代表本地文件系统的文件。
最佳答案
它必须了解您对哪个平台感兴趣,当前平台是一个很好的猜测!
在 Linux 上 /tmp
是绝对的。在 Windows 上则不然 - 它与您当前的驱动器相关。
关于java - 当 File 类与平台无关时,为什么 File.isAbsolute() 与平台相关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154754/