How to find disk space in java

File class in java provides methods that are useful for finding total, free and usable disk space. Can be used like this:


package com.bharat.test;

import java.io.File;

public class DiskSpaceCheck
{

public static void main(String... args)
{

File disk = new File("c:");
System.out.println("Total Space : " + disk.getTotalSpace());
System.out.println("Free Space : " + disk.getFreeSpace());
System.out.println("Usable Space : " + disk.getUsableSpace());

}
}

On my machine the output was


Total Space : 160029995008
Free Space : 86167339008
Usable Space : 86167339008

Reference: http://docs.oracle.com/javase/6/docs/api/java/io/File.html

Advertisements

, , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: