File listRoots() method in Java with examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. Function Signature: public static File[] listRoots() Syntax: 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 Java // Java program to demonstrate // the use of File.listRoots() method import java.io.*; public class GFG { public static void main(String args[]) { // roots of the path name File root[] = File.listRoots(); // check if the root is null or not if (root != null) { System.out.print("Roots are: "); // display the roots of the path name for (int i = 0; i < root.length; i++) { System.out.print(root[i].getPath() + " "); } } else System.out.println("There are no roots"); } } Output: 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 Comment More infoAdvertise with us Next Article Java floor() method with Examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads List indexOf() Method in Java with Examples This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. Example:Java// Java Program to Implement List // indexOf() Method import java.util.*; class GFG { public static void main (String[] args) { // List Created Li 2 min read Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read Java floor() method with Examples The java.lang.Math.floor() returns the double value that is less than or equal to the argument and is equal to the nearest mathematical integer. Note: If the argument is Integer, then the result is Integer.If the argument is NaN or an infinity or positive zero or negative zero, then the result is th 2 min read TreeSet floor() method in Java with Examples The floor() method of java.util.TreeSet<E> class is used to return the greatest element in this set less than or equal to the given element, or null if there is no such element. Syntax: public E floor(E e) Parameters: This method takes the value e as a parameter which is to be matched. Return 2 min read TreeSet floor() method in Java with Examples The floor() method of java.util.TreeSet<E> class is used to return the greatest element in this set less than or equal to the given element, or null if there is no such element. Syntax: public E floor(E e) Parameters: This method takes the value e as a parameter which is to be matched. Return 2 min read TreeSet floor() method in Java with Examples The floor() method of java.util.TreeSet<E> class is used to return the greatest element in this set less than or equal to the given element, or null if there is no such element. Syntax: public E floor(E e) Parameters: This method takes the value e as a parameter which is to be matched. Return 2 min read Like