JAVA列出文件夹中的所有文件

来源:互联网 发布:大数据和数据挖掘教程 编辑:程序博客网 时间:2024/05/17 08:15

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 stubFile 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不是目录。");}}}


原创粉丝点击