File getTotalSpace() method in Java with examples Last Updated : 20 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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(); Parameters: This method does not accept any parameter. Return Value: The function returns long data type represents size of the partition in bytes Exception: This method throws SecurityException if the method does not allow file to be created Below programs illustrates the use of getTotalSpace() function: Example 1: The file "F:\\program.txt" is a existing file in F: Directory . Java // Java program to demonstrate // getTotalSpace() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Create an abstract pathname (File object) File f = new File("F:\\program.txt"); // Display the Total size of the partition // using the getTotalSpace() function System.out.println("Total Space: " + f.getTotalSpace()); } } Output: Total Space: 355947507712 Example 2: The file "F:\\program1.txt" does not exist file in F: Directory . Java // Java program to demonstrate // getTotalSpace() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Create an abstract pathname (File object) File f = new File("F:\\program1.txt"); // Display the Total size of the partition // using the getTotalSpace() function System.out.println("Total Space: " + f.getTotalSpace()); } } Output: Total Space: 0 Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file. Comment More infoAdvertise with us Next Article Files getFileStore() method in Java with Examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads 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 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 File getFreeSpace() method in Java with examples The getFreeSpace() 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 gives a hint of the unallocated space of the partition but does not give any gua 2 min read FileStore getUsableSpace() method in Java with Examples 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() th 2 min read Files getFileStore() method in Java with Examples getFileStore() method of java.nio.file.Files help us to return the FileStore object which represents the file store where a file is located. Once you get a reference to the FileStore you can apply filestore type of operation to get information of filestore. Syntax: public static FileStore getFileSto 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 Like