import java.io.File; import javax.swing.filechooser.FileSystemView; /** 显示本地磁盘根盘符,显示桌面路径 */ public class RDDemo { static File[] files; public static void main(String[] args) { FileSystemView sys = FileSystemView.getFileSystemView(); files = sys.getRoots(); System.out.println(files.length); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } files = File.listRoots(); System.out.println(files.length); for (int i = 0; i < files.length; i++) { System.out.println(files[i] + " -- " + sys.getSystemTypeDescription(files[i])); } } }