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;


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



, , ,

  1. Leave a comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: