The code below demonstrates how to obtain file system root available on your system. In Linux, you will have a single root (/
) while on Windows you could get C:\
or D:\
that represent the root drives.
package org.kodejava.io;
import java.io.File;
public class FileSystemRoot {
public static void main(String[] args) {
// List the available filesystem roots.
File[] root = File.listRoots();
// Iterate the entire filesystem roots.
for (File file : root) {
System.out.println("Root: " + file.getAbsolutePath());
}
}
}
The result of the code snippet:
Root: C:\
Root: D:\
Root: F:\
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024