Hi I have search the net to an extent that I can not more and I still have not found the answer, so I am someone here can tell me, I want to be able to list all local drives in a system, but excluding USB. Network, DVD, etc

This is what I have but I don't know how to pickup only the Local Drive

public class ListAllDrives {
public static void main(String[] args) {

      List <File>files = Arrays.asList(File.listRoots());
      for (File drv : files) {
          String s1 = FileSystemView.getFileSystemView().getSystemDisplayName (drv);
          String s2 = FileSystemView.getFileSystemView().getSystemTypeDescription(drv);
          System.out.println(s2 + " : " + s1);

Any suggestion would be greatly appreciated.

7 Years
Discussion Span
Last Post by gcclinux

Hello again and although I know I ask allot of questions I also like to provide answers when I figure them out and in this case I have achived it with something even more symple than I expected.

public class ListLocalDrives {
public static void main(String[] args) {

      List <File>root = Arrays.asList(File.listRoots());
      for (File drv : root) {
        String name = FileSystemView.getFileSystemView().getSystemDisplayName (drv);
        String type = FileSystemView.getFileSystemView().getSystemTypeDescription(drv);
        String local = "Local Disk";

        if ( (type).equals(local) ){
            System.out.println(type + " : " + name);

I hope this helps some of those people asking the same questions online.


You are absolutely correct unfortunately this option only covers Windows and in English I do apologies for those using alternative operating systems and different languages.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.