Senin, 29 Februari 2016

How To Get Total Space And Free Space Using Java I/O

Following the Java I/O code example to get total space and free space on a drive:

Source Code


File Name: TotalSpaceAndFreeSpaceDemo.java

import java.io.File;

public class TotalSpaceAndFreeSpaceDemo {
 public static void main(String[] args){
  File file = new File("D:");
     long totalSpace = file.getTotalSpace();
     System.out.println("Total space on drive " + file + " = " + totalSpace + "bytes");

     // Check the free space in C:
     long freeSpace = file.getFreeSpace();
     System.out.println("Free space on drive " + file + " = " + freeSpace + "bytes");
 }
}

Output


Total space on drive D: = 299266732032bytes
Free space on drive D: = 38464524288bytes

Tidak ada komentar:

Posting Komentar