Home  >  Article  >  Java  >  Java Example - View System Root Directory

Java Example - View System Root Directory

黄舟
黄舟Original
2017-02-13 10:24:101129browse

The following example demonstrates using the listRoots() method of the File class to output all root directories of the system:

/*
 author by w3cschool.cc
 Main.java
 */

import java.io.*;

class Main{
   public static void main(String[] args){
      File[] roots = File.listRoots();
      System.out.println("系统所有根目录:");
      for (int i=0; i < roots.length; i++) {
         System.out.println(roots[i].toString());
      }
   }
}

The output result of running the above code is:

系统所有根目录:
C:\
D:\
E:\
F:\
G:\
H:\

The above is the Java example - View the contents of the system root directory. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn