Detect the storage device typeTag(s): IO


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:)
      */

  }
}

blog comments powered by Disqus