package com.bb2c.product.web.action;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ReadDirector {
private static String dir_name = "E:\pic";
@SuppressWarnings("unchecked")
public static void main(String[] args) {
ReadDirector rd = new ReadDirector();
List filenames = rd.getFiles(dir_name);
for (int i = 0; i < filenames.size(); i++) {
String str = (String) filenames.get(i);
System.out.println("第" + (i + 1) + "文件名是:" + str);
}
}
@SuppressWarnings("unchecked")
public List getFiles(String dirname) {
File dir = new File(dirname);
File[] files = dir.listFiles();
List file_names = new ArrayList();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {// 判断是否是目录
file_names.add(files[i].getName() + "=>它是一个文件夹");
}
if (files[i].isHidden()) {// 判断是否是隐藏文件
file_names.add(files[i].getName() + "=>它是一个隐藏文");
}
if (files[i].isFile() && (!files[i].isHidden())) {// 判断是否是文件并不能是隐藏文件
file_names.add(files[i].getName());
}
}
return file_names;
}
}