import java.io.*;public class ListRoot {
public static void main(String[] agrs) {
File file = new File("//");
File[] list = file.listRoots();
for(int i = 0; i < list.length; i++) {
System.out.println(list[i]);
}
}
}我得到的结果:
A:\
C:\
D:\
E:\
F:\

解决方案 »

  1.   

    File还有这样一个构建器:
    public File(URI&nbsp;uri)Creates a new File instance by converting the given file: URI into an abstract pathname. The exact form of a file: URI is system-dependent, hence the transformation performed by this constructor is also system-dependent. For a given abstract pathname f it is guaranteed that new File( f.toURI()).equals( f) so long as the original abstract pathname, the URI, and the new abstract pathname are all created in (possibly different invocations of) the same Java virtual machine. This relationship typically does not hold, however, when a file: URI that is created in a virtual machine on one operating system is converted into an abstract pathname in a virtual machine on a different operating system.
    Parameters:
    uri - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
    Throws:
    NullPointerException - If uri is null
    IllegalArgumentException - If the preconditions on the parameter do not hold
    Since:
    1.4
    See Also:
    toURI(), URI你可以试试FTP,看看那个是文件夹,那个是文件
      

  2.   

    for:pcdos(流浪) (  ) 呵呵,我也没有办法来确定这个驱动器是不是网络驱动器,你有办法吗?欢迎交流:49074333,谢谢