
Apache Commons IO - Utility Classes
- Apache Commons IO - IOUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - IOCase
- Apache Commons IO - LineIterator
Apache Commons IO - Filter Classes
- Apache Commons IO - NameFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - AndFileFilter
- Apache Commons IO - FileEntry
Apache Commons IO - Comparator Classes
- Apache Commons IO - NameFileComparator
- Apache Commons IO - SizeFileComparator
- LastModifiedFileComparator
Apache Commons IO - Stream Classes
Apache Commons IO - Useful Resources
Apache Commons IO - FileSystemUtils Class
Overview
FileSystemUtils class provides method to get the free space on a disk drive.
Class Declaration
Following is the declaration for org.apache.commons.io.FileSystemUtils Class −
public class FileSystemUtils extends Object
Example - Getting Free Space of a drive in Bytes
CommonsIoTester.java
package com.tutorialspoint; import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class CommonsIoTester { public static void main(String[] args) throws IOException { System.out.println("Free Space " + FileSystemUtils.freeSpace("C:/") + " Bytes"); } }
Output
It will print the following result −
Free Space 186157182976 Bytes
Example - Getting Free Space of a drive in KiloBytes
CommonsIoTester.java
package com.tutorialspoint; import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class CommonsIoTester { public static void main(String[] args) throws IOException { System.out.println("Free Space " + FileSystemUtils.freeSpaceKb("C:/") + " KB"); } }
Output
It will print the following result −
Free Space 181794512 KB
Example - Getting Free Space of a drive in KiloBytes with timeout
CommonsIoTester.java
package com.tutorialspoint; import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class CommonsIoTester { public static void main(String[] args) throws IOException { System.out.println("Free Space " + FileSystemUtils.freeSpaceKb("C:/",1000) + " KB"); } }
Output
It will print the following result −
Free Space 181794512 KB
Advertisements