JAVA列出文件夹中的所有文件
It shows that we can list all the files in a specified folder, if it exists.
package com.han; import java.io.File; /** * It shows that we can list all the files in a specified folder, if it exists. * @author han * */ public class ListFiles { public static void main(String[] args) { // TODO Auto-generated method stub File file=new File("/home/han/Documents/word"); // System.out.println(file.getName()); if (file.isDirectory()){ File[] fl=file.listFiles(); for (int i=0;i<fl.length;i++){ System.out.println(fl[i]); } } else{ System.out.println("File不是目录。"); } } }