java - 当 File 类与平台无关时,为什么 File.isAbsolute() 与平台相关?

标签 java file

来自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/

相关文章:

java - 错误 yarn.ApplicationMaster : User class threw exception: java. lang.NoClassDefFoundError: scala/Function0$class

java - Hibernate 子查询问题

python - 比较两个文件的相似性,而不是常见问题

android - Eclipse-崩溃后文件为空

file - 为什么 lsof 报告的打开文件数高于 ulimit 的 "open file"输出

java - Android文件描述符泄漏调试

java - 从属性指定数组列表类型

java - 如何减慢AI?

java - 无法复制音频文件

objective-c - 应用选择 - Cocoa