code_junkie

Acquiring drive names (as opposed to drive letters) in Java

Nov 13th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import javax.swing.filechooser.FileSystemView;
  5.  
  6. public class Test2 {
  7. public static void main(String args[]){
  8.  
  9. List <File>files = Arrays.asList(File.listRoots());
  10. for (File f : files) {
  11. String s1 = FileSystemView.getFileSystemView().getSystemDisplayName (f);
  12. String s2 = FileSystemView.getFileSystemView().getSystemTypeDescription(f);
  13. System.out.println("getSystemDisplayName : " + s1);
  14. System.out.println("getSystemTypeDescription : " + s2);
  15. }
  16. /* output (French WinXP)
  17.  
  18. getSystemDisplayName :
  19. getSystemTypeDescription : Disquette 3½ pouces
  20.  
  21. getSystemDisplayName : REGA1 (C:)
  22. getSystemTypeDescription : Disque local
  23.  
  24. getSystemDisplayName :
  25. getSystemTypeDescription : Lecteur CD
  26.  
  27. getSystemDisplayName : My Book (F:)
  28. getSystemTypeDescription : Disque local
  29. */
  30. }
  31. }
Add Comment
Please, Sign In to add comment