集册 Java实例教程 列出目录的内容

列出目录的内容

欢马劈雪     最近更新时间:2020-01-02 10:19:05

454
列出目录的内容
//时 代 J a v a 公 众 号 - nowjava.com 提 供

import java.io.*;

 

public class Main {

 

  public static void main(String[] args) {

    File file = new File("C://FileIO");

     String[] files = file.list();

   

     System.out.println("Listing contents of " + file.getPath());

     for(int i=0 ; i < files.length ; i++)

     {

       System.out.println(files[i]);

     }

  }

}