skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Wednesday, October 31, 2012

calculate the free disk space

Posted by Raju Gupta at 3:09 AM – 0 comments
 

To calculate available disk space using Java   

import java.io.IOException; 
  
import org.apache.commons.io.FileSystemUtils; 
  
public class DiskSpace { 
    public static void main(String[] args) { 
        try { 
  
            //calculate free disk space 
            double freeDiskSpace = FileSystemUtils.freeSpaceKb("C:");  
  
            //convert the number into gigabyte 
            double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024; 
  
            System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } 
}



Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger