File listRoots() method in Java with examples
The listRoots() method is a part of File class. The listRoots() function returns the root directories of all the available file System roots. It is guaranteed that the pathname of any file on the system will begin with any one of these roots.
public static File listRoots()
Parameters: The function do not requires any parameters.
Return Value: The function returns File array, which contains all the file system roots .
Exception: This method do not throw any exceptions
Below programs will illustrate the use of listRoots() function:
Example 1: Try display all the root directories of the system
Roots are: C:\ D:\ E:\ F:\ G:\
The programs might not run in an online IDE. please use an offline IDE and set the path of the file