FileSystem getFileStores() Method in Java with Examples
Last Updated :
10 Sep, 2019
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:
import java.nio.file.*;
import java.util.Iterator;
public class GFG {
public static void main(String[] args)
{
Path path = Paths.get( "C:\\Users\\"
+ "asingh.one\\Documents" );
FileSystem fs = path.getFileSystem();
Iterable<FileStore> it = fs.getFileStores();
Iterator<FileStore> iterator = it.iterator();
System.out.println( "FileStrores are:\n" );
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
|
Output:
Program 2:
import java.nio.file.*;
import java.util.Iterator;
public class GFG {
public static void main(String[] args)
{
Path path = Paths.get( "D:\\eclipse" );
FileSystem fs = path.getFileSystem();
Iterable<FileStore> it = fs.getFileStores();
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()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...