Home > Java > javaTutorial > body text

Java Example - View System Root Directory

黄舟
Release: 2017-02-13 10:24:10
Original
1133 people have browsed it

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());
      }
   }
}
Copy after login

The output result of running the above code is:

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

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)!



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template