The getFileStores() method of java.nio.file.FileSystem is used to return an iterable of FileStore object to iterate over the underlying file stores. The elements contained by the returned iterator are the FileStores for this file system. When an input-output error occurs, because of the inaccessibility to a file store, then it is not returned by the iterator.
Syntax:
public abstract Iterable<FileStore> getFileStores()
Parameters: This method does not accept anything.
Return value: This method returns an object to iterate over the backing file stores.
Below programs illustrate getFileStores() method:
Program 1:
| // Java program to demonstrate// java.nio.file.FileSystem.getFileStores() method Âimportjava.nio.file.*;importjava.util.Iterator; ÂpublicclassGFG {    publicstaticvoidmain(String[] args)    { Â        // create object of Path        Path path = Paths.get("C:\\Users\\"                              + "asingh.one\\Documents"); Â        // get FileSystem object        FileSystem fs = path.getFileSystem(); Â        // apply getFileStores() methods        Iterable<FileStore> it = fs.getFileStores(); Â        // print all FileStore contains by this system        Iterator<FileStore> iterator = it.iterator();        System.out.println("FileStrores are:\n");        while(iterator.hasNext()) {            System.out.println(iterator.next());        }    }} | 
Output:
Program 2:
| // Java program to demonstrate// java.nio.file.FileSystem.getFileStores() method Âimportjava.nio.file.*;importjava.util.Iterator; ÂpublicclassGFG {    publicstaticvoidmain(String[] args)    { Â        // create object of Path        Path path = Paths.get("D:\\eclipse"); Â        // get FileSystem object        FileSystem fs = path.getFileSystem(); Â        // apply getFileStores() methods        Iterable<FileStore> it = fs.getFileStores(); Â        // print all FileStore contains by this system        Iterator<FileStore> iterator = it.iterator();        System.out.println("FileStores on system are:\n");        while(iterator.hasNext()) {            System.out.println(iterator.next());        }    }} | 
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileSystem.html#getFileStores()


 
                                    








