gpt4 book ai didi

java - 在 Java 中获取驱动器名称(而不是驱动器号)

转载 作者:搜寻专家 更新时间:2023-10-30 21:03:40 25 4
gpt4 key购买 nike

在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com