Java Directory list content using SimpleFileVisitor
import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; class ClassFileRemover extends SimpleFileVisitor<Path> { public FileVisitResult visitFile(Path file, BasicFileAttributes attr) throws IOException { if (file.toString().endsWith(".class")) { Files.delete(file);//w ww . ja v a2 s . c o m } return FileVisitResult.CONTINUE; } } public class Main { public static void main(String args[]) throws IOException { Files.walkFileTree(Paths.get("f:"), new ClassFileRemover()); } }