FileSystem getRootDirectories() method in Java with Examples Last Updated : 18 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The getRootDirectories() method of a FileSystem class is used to return an Iterator object to iterate over the paths of the root directories for this File System. A file system is composed of a number of distinct file hierarchies, each with its own top-level root directory and each element in the returned iterator by this method correspond to the root directory of a distinct file hierarchy. The order of the elements is not defined. When a security manager is installed and If access to root directory is denied then the root directory is not returned by the iterator. Syntax: public abstract Iterable getRootDirectories() Parameters: This method accepts nothing. Return value: This method returns an Iterable object to iterate over the root directories. Below programs illustrate the getRootDirectories() method: Program 1: Java // Java program to demonstrate // FileSystem.getRootDirectories() method import java.nio.file.FileSystem; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Iterator; public class GFG { public static void main(String[] args) { // create object of Path Path path = Paths.get( "C:\\Movies\\document.txt"); // get FileSystem object FileSystem fs = path.getFileSystem(); // apply getRootDirectories() methods Iterable<Path> it = fs.getRootDirectories(); // print all Path Iterator<Path> iterator = it.iterator(); System.out.println("Paths are:"); while (iterator.hasNext()) { System.out.println(iterator.next()); } } } Output: Program 2: Java // Java program to demonstrate // FileSystem.getRootDirectories() method import java.nio.file.FileSystem; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Iterator; public class GFG { public static void main(String[] args) { // create object of Path Path path = Paths.get( "E:\\Tutorials\\file.txt"); // get FileSystem object FileSystem fs = path.getFileSystem(); // apply getRootDirectories() methods Iterable<Path> it = fs.getRootDirectories(); // print all Path Iterator<Path> iterator = it.iterator(); iterator.forEachRemaining((System.out::println)); } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileSystem.html#getRootDirectories() Comment More infoAdvertise with us Next Article FileSystem getRootDirectories() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java.nio.file package Java-FileSystem Practice Tags : Java Similar Reads 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 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 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 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 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 Like