Home Tutorial Java Corejava Display total disk drive capacity

 
 

Display total disk drive capacity
Posted on: April 20, 2010 at 12:00 AM
Advertisement
This tutorial demonstrate how to display total disk capacity of each drive.

Description:

This example will demonstrate how to get the total disk space of your drives.                        The getTotalSpace() method introduced in the Jdk 6 and found in java.io.File. This method gets the total disk capacity in the bytes.

Code:

import java.io.File;

public class TotalDiskSpace {
  public static void main(String[] args) {
    File[] drive = File.listRoots();

    for (int i = 0; i < drive.length; i++) {
      System.out.println(drive[i]);
      long totalbyte = drive[i].getTotalSpace();
      double temp = Math.pow(10243);
      double totalgb = totalbyte / temp;
      System.out.println("Total space in Bytes " + totalbyte);
      System.out.println("Total space in GB " + totalgb);
    }
  }
}

Output:

The output of this example depends upon number of drive you have and the total disk capacity.

Note : As it search for drive it will take time to display the result so wait till it complete searching.

Sample output:

 

 

Advertisement

Related Tags for Display total disk drive capacity :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 20, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com