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
*/
}
}
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:)
*/
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com