在我的 Windows 机器上,我的主硬盘有字母 C: 和名称“Local disk”。
要在 Windows 上的 Java 中列出驱动器盘符,File 对象具有静态 listRoots() 方法。但是我找不到在 Windows 上获取驱动器名称(而不是驱动器号)的方法。
有人试过吗?
最佳答案
啊,是的,您需要获取 FileSystemView 对象并使用 getSystemDisplayName . (我曾经用 Java 实现了一个文件系统浏览器)。
虽然它并不完美,但它会让你得到这个名字。来自文档:
Name of a file, directory, or folder as it would be displayed in a system file browser. Example from Windows: the "M:\" directory displays as "CD-ROM (M:)" The default implementation gets information from the ShellFolder class.
关于java - 在 Java 中获取驱动器名称(而不是驱动器号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/462110/