现在的位置: 首页 > 综合 > 正文

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

2014年03月06日 ⁄ 综合 ⁄ 共 487字 ⁄ 字号 评论关闭

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

}

抱歉!评论已关闭.