List the available system roots in Java

Use the method listRoots in the File class. Notice that this is filesystem dependent. On Unix, there is only one system root: “/”. On Windows, it depends on drives that are mapped.
Here’s an example:

Main.java:

import java.io.*;
   
public class Main {
   public static void main(String[] args) {
      File[] roots = File.listRoots();
      for (int i=0; i<roots.length; i++) {
         System.out.println(roots[i]);
      }
   }
}

outputs on my machine:

A:
C:
D:
E: