Calculating Free Disk Space using Apache Commons IO

Calculating Free Disk Space using Apache Commons IO


Posted in : Core Java Posted on : November 5, 2011 at 7:05 PM Comments : [ 0 ]

In this tutorial, you will learn how to calculate free unused hard space using Apache Commons IO.

Calculating Free Disk Space using Apache Commons IO

In this tutorial, you will learn how to calculate free unused hard space using Apache Commons IO.

You can download Apache Commons IO library from here.

EXAMPLE

package com.devmanuals;

import java.io.IOException;
import org.apache.commons.io.FileSystemUtils;
public class ReaddiskSpace {
public static void main(String[] args) {
try {

//Passing disk name to calculate free disk space
double freeDiskSpace = FileSystemUtils.freeSpaceKb("C:");

//Number into Gigabyte(GB) Convrsion
double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;

System.out.println("Free Disk Space :" + freeDiskSpaceGB+" GB");
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getCause());
}
}
}

OUTPUT


Free Disk Space : 27.109092712402344 GB                

Download Source Code

 

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics