A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/dir_root.htm below:

How to display root directories in the system using Java

How to display root directories in the system using Java Problem Description

How to display root directories in the system?

Solution

Following example shows how to find root directories in your system using listRoots() method of File class.

import java.io.*;

public class Main { 
   public static void main(String[] args) { 
      File[] roots = File.listRoots();
      System.out.println("Root directories in your system are:");
      
      for (int i = 0; i < roots.length; i++) {
         System.out.println(roots[i].toString());
      } 
   }
}
Result

The above code sample will produce the following result. The result may vary depending on the system & operating system. If you are using Unix system you will get a single root '/'.

Root directories in your system are:
C:\
D:\
E:\
F:\
G:\
H:\

java_directories.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4