tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Commons IO > Basic > Get Free Space

Get Free Space 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using FileSystemUtils.freeSpaceKb() API. It returns the free space on a drive or volume in kilobytes.

File Name  :  
com/bethecoder/tutorials/commons_io/tests/GetFreeSpace.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.commons_io.tests;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileSystemUtils;

public class GetFreeSpace {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    
    String driveName = "C:";
    System.out.println("Drive [" + driveName + "] free space : " 
        FileSystemUtils.freeSpaceKb(driveName" KB");
    
    File file = new File("C:/Test/Test.java");
    System.out.println("Free space of the drive containing file [" + file + "] : " 
        FileSystemUtils.freeSpaceKb(file.getAbsolutePath()) " KB");
    
    //Get the disk size of drive containing working directory (Its C:\ drive in my case)
    System.out.println("Current drive free space : " + FileSystemUtils.freeSpaceKb() " KB");
  
  }
}
   

It gives the following output,
Drive [C:] free space : 44242924 KB
Free space of the drive containing file [C:\Test\Test.java] : 44242924 KB
Current drive free space : 44242924 KB


                    Print

   



Books Recommendation

 
 
bl  br