How to get Total Space and Free Space on any drive or C: drive?

Below java code show how to get total space and free space

/****************************************************************************************
 * Created on 08-2011 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.javaio;

import java.io.File;

/**
 * Created by http://kodehelp.com
 * Date: 8/27/11
 */
public class TotalAndFreeSpace {
    public static void main(String args[]){
        File file = new File("C:");
        //check total space in C:
        long totalSpace = file.getTotalSpace();
        System.out.println("Total space on " + file + " = " + totalSpace + "bytes");
        // Check the free space in C:
        long freeSpace = file.getFreeSpace();
        System.out.println("Free space on " + file + " = " + freeSpace + "bytes");
    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.