How can I get list of all drives but also get the corresponding drive type (removable,local disk, or cd-rom,dvd-rom… etc)?

前端 未结 7 1057
猫巷女王i
猫巷女王i 2020-12-01 14:42

How can I get list all drives but also get the corresponding drive type (removable,local disk, or cd-rom,dvd-rom... etc)?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 15:00

    With this code you can get all drives and its type description

    File[] paths;
    FileSystemView fsv = FileSystemView.getFileSystemView();
    
    // returns pathnames for files and directory
    paths = File.listRoots();
    
    // for each pathname in pathname array
    for(File path:paths)
    {
        // prints file and directory paths
        System.out.println("Drive Name: "+path);
        System.out.println("Description: "+fsv.getSystemTypeDescription(path));
    }
    

提交回复
热议问题