skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, September 17, 2012

Using Apache Commons IO in JAVA calculate free disk space

Posted by Admin at 11:20 AM – 0 comments
 

Calculating free disk space using Apache Commons I in JAVA


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

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




Labels: Java IO Example

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