FileStore getUsableSpace() method in Java with Examples Last Updated : 03 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The getUsableSpace() method of a FileStore class is used to return the number of bytes available to this Java virtual machine on the file store. This method is useful to check free space. This method returns the available usable space as a long value. Syntax: public abstract long getUsableSpace() throws IOException Parameters: This method accepts nothing. Return value: This method returns the available usable space as a long value. Exception: This method throws IOException if an I/O error occurs. Below programs illustrate the getUsableSpace() method: Program 1: Java // Java program to demonstrate // FileStore.getUsableSpace() method import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) { // create the object of Path Path path = Paths.get( "E:\\Tutorials\\file.txt"); // get FileStore object try { FileStore fs = Files.getFileStore(path); // print FileStore name and Total usable space System.out.println("FileStore Name: " + fs.name()); long bytes = fs.getUsableSpace(); long sizeInGB = bytes / (1024 * 1024); System.out.println("Usable Space: " + sizeInGB + " MB"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Output: Program 2: Java // Java program to demonstrate // FileStore.getUsableSpace() method import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) { // create the object of Path Path path = Paths.get( "C:\\Movies\\001.txt"); // get FileStore object try { FileStore fs = Files.getFileStore(path); // print FileStore name and Total usable space System.out.println("FileStore Name: " + fs.name()); long bytes = fs.getUsableSpace(); long sizeInGB = bytes / (1024); System.out.println("Usable Space: " + sizeInGB + " KB"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileStore.html#getUsableSpace() Comment More infoAdvertise with us Next Article FileStore getUsableSpace() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java.nio.file package Java-FileStore Practice Tags : Java Similar Reads File getUsableSpace() method in java with examples The getUsableSpace() function is a part of File class in Java . This function returns the unallocated size of the partition denoted by the abstract pathname, if the pathname does not exist then it returns 0L. This function is more accurate than the getFreeSpace() function as it returns the free spac 2 min read FileStore getTotalSpace() method in Java with Examples The getTotalSpace() method of a FileStore class is used to return total size of the file store, in bytes. This method returns this total size as a long value. Syntax: public abstract long getTotalSpace() throws IOException Parameters: This method accepts nothing. Return value: This method returns th 2 min read FileStore getUnallocatedSpace() method in Java with Examples The getUnallocatedSpace() method of a FileStore class is used to get the number of unallocated bytes in the file store. This method is useful to check free space. This method returns the available unallocated space as a long value.Syntax: public abstract long getUnallocatedSpace() throws IOException 2 min read File getTotalSpace() method in Java with examples The getTotalSpace() function is a part of File class in Java . This function returns the total size of the partition denoted by the abstract pathname, if the pathname does not exist then it returns 0L. Function signature: public long getTotalSpace() Syntax: long var = file.getTotalSpace(); Parameter 2 min read FileStore getBlockSize() method in Java with Examples The getBlockSize() method of a FileStore class is used to return the number of bytes per block in this file store Object. Every File storage is organized into discrete sequences of bytes called blocks and a block is the smallest storage unit of a file store. Every read and write operation is perform 2 min read Like