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 |
[ 0 ] Comments