日期:2014-05-20 浏览次数:20747 次
public class TestFileFilter {
/**
* @param args
*/
public static void main(String[] args) {
String pathname = ".";
File file = new File(pathname);
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
};
File[] listFiles = file.listFiles(filter);
for (File file2 : listFiles) {
System.out.println(file2.getName());
}
}
}
file.listFiles(new FileFilter(){
public boolean accept(File file){
return file.isDirectory();
}
})
import java.io.File;
import java.io.FileFilter;
public class OnlyFolder {
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("D:" + File.separator + "appserver");
File[] files = file.listFiles(new UserFilter());
for(File f : files) {
System.out.println("是否是文件夹:" + f.isDirectory() + "名称:" + f.getName());
}
}
}
class UserFilter implements FileFilter {
@Override
public boolean accept(File file) {
if(file != null && file.isDirectory())
return true;
else
return false;
}
}