Detect the storage device type

javax.swing.filechooser.FileSystemView provides a way to detect the type of a particular device.

import java.io.File;
import java.util.Arrays;
import java.util.List;
import javax.swing.filechooser.FileSystemView;

public class Test2 {
    public static void main(String args[]){
      
      List <File>files = Arrays.asList(File.listRoots());
      for (File f : files) {
        String s = FileSystemView.getFileSystemView().getSystemTypeDescription(f);
        System.out.println("*" + s);
      }
      /* output (French WinXP)

            *Disquette 3½ pouces
            *Disque local
            *Lecteur CD
            *Disque local
      */
    }
}
As you can see the output is localized (from the OS).

The following output the name or label of the storage device :

import java.io.File;
import java.util.Arrays;
import java.util.List;
import javax.swing.filechooser.FileSystemView;

public class Test2 {
    public static void main(String args[]){
      
      List <File>files = Arrays.asList(File.listRoots());
      for (File f : files) {
        String s = FileSystemView.getFileSystemView().getSystemDisplayName(f);        
        System.out.println("*" + s);
      }
      /* output (French WinXP)

            *
            *REGA1 (C:)
            *
            *My Book (F:)
      */
      
    }
  }



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2010
[ home ]