import java.io.File;
import java.io.FilenameFilter;
public class Main {
public static void main(String[] args) {
File games = new File("C:\\Test");
File[] files = games.listFiles();
for (File file : files) {
System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file"));
}
String[] xfiles = games.list();
for (String file : xfiles) {
System.out.println("File = " + file);
}
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.endsWith(".txt")) {
return true;
}
return false;
}
};
File[] yfiles = games.listFiles(filter);
for (File doc : yfiles) {
System.out.println("Doc file = " + doc);
}
}
}
|