import java.io.File; class FilteredDirectoryTree { public static void main(String args[]) { tree(args[0], "txt"); } public static void tree(String filename, String suffix) { File file = new File(filename); if (!file.isDirectory()) { if (suffix == null || filename.endsWith(suffix)) System.out.println(filename); return; } String files[] = file.list(); for (int i = 0; i < files.length; i++) { tree(filename + File.separator + files[i], suffix); } } }