Saturday 22 October 2016

Listing all drives with type, total space and free space in Java



import java.io.File;

import javax.swing.filechooser.FileSystemView;

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

      FileSystemView fsv = FileSystemView.getFileSystemView();

      File[] drives = File.listRoots();

      if (drives != null && drives.length > 0) {

         for (File drive : drives) {
            System.out.print("Drive name: "+drive);
            System.out.print(",\tType: "+fsv.getSystemTypeDescription(drive));
            System.out.print(",\tTotal space: "+drive.getTotalSpace());
            System.out.print(",\tFree space: "+drive.getFreeSpace());
            System.out.println();
         }
      }
   }
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...