问题描述
对于我正在进行的项目。我需要在文件系统上查找可执行文件。对于UNIX衍生产品,我假设用户在强大的$ PATH变量中有文件,但在Windows上没有这样的东西。
For a project I'm working on. I need to look for an executable on the filesystem. For UNIX derivatives, I assume the user has the file in the mighty $PATH variable, but there is no such thing on Windows.
我可以放心地假设文件位于最深入文件系统的2个级别,但我不知道它将是什么驱动器。我必须尝试所有驱动器,但我无法弄清楚如何列出所有可用的驱动器(分配了一个字母)。
I can safely assume the file is at most 2 levels deep into the filesystem, but I don't know on what drive it will be. I have to try all drives, but I can't figure out how to list all available drives (which have a letter assigned to it).
任何帮助?
编辑:我知道%PATH%变量,但它不像UNIX系统那样集成。例如,我正在寻找的应用程序是OpenOffice。此类软件通常不会在%PATH%中。
I know there is a %PATH% variable, but it is not as integrated as in UNIX systems. For instance, the application I'm looking for is OpenOffice. Such software would not be in %PATH%, typically.
推荐答案
File[] roots = File.listRoots();
for(int i = 0; i < roots.length ; i++)
System.out.println("Root["+i+"]:" + roots[i]);
google:list drives java,first hit: - )
google: list drives java, first hit:-)
这篇关于在Java中查找所有驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!