Files getFileStore() method in Java with Examples Last Updated : 13 Apr, 2023 Comments Improve Suggest changes Like Article Like Report 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 getFileStore(Path path) throws IOException Parameters: This method accepts a parameter path which is the path to the file to get FileStore. Return value: This method returns the file store where the file is stored. Exception: This method will throw following exceptions: IOException: if an I/O error occursSecurityException: In the case of the default provider, and a security manager is installed, the SecurityManager.checkgetFileStore(String) method is invoked to check to getFileStore access to the file Below programs illustrate getFileStore(Path) method: Program 1: Java // Java program to demonstrate // Files.getFileStore() method import java.io.IOException; import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path Path path = Paths.get( "D:\\Work\\Test\\file1.txt"); // get FileStore object try { FileStore fs = Files.getFileStore(path); // print FileStore name and block size System.out.println("FileStore Name: " + fs.name()); System.out.println("FileStore BlockSize: " + fs.getBlockSize()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Output: Program 2: Java // Java program to demonstrate // Files.getFileStore() method import java.io.IOException; import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path Path path = Paths.get("C:\\data\\db"); // get FileStore object try { FileStore fs = Files.getFileStore(path); // print FileStore details System.out.println("FileStore:" + fs.toString()); System.out.println("FileStore Free Space: " + fs.getUnallocatedSpace() + " Bytes"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Output: Reference: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#getFileStore(java.nio.file.Path) Comment More infoAdvertise with us Next Article Files getFileStore() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java.nio.file package Java-Files Practice Tags : Java Similar Reads 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 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 FileSystem getSeparator() method in Java with Examples The getSeparator() method of a FileSystem class is used to return the name separator for this file system as a string. The name separator is used to separate names in a path string. In the case of the default provider, this method returns the same separator as String.Syntax: public abstract String g 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 name() method in Java with Examples The name() method of a FileStore class is used to return the name of this file store as a String. The format of the name is typically the name of the storage pool or volume. The string returned by this method may differ from the string returned by the toString() method. Syntax: public abstract Strin 2 min read Like