Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package deleteme;
- import java.io.File;
- import java.util.Stack;
- public class FindFiles {
- public static void main(String[] args) {
- File root = new File(".");
- Stack<String> stack = new Stack<>();
- stack.push(root.getAbsolutePath());
- while (!stack.isEmpty()) {
- File next = new File(stack.pop());
- boolean isFile = next.isFile();
- System.out.printf("[type: %s] [path: %s]%n", (isFile ? "file" : "dir"), next.getAbsolutePath());
- if (!isFile) {
- String [] childnames = next.list();
- if (childnames != null) {
- for (String childname : childnames) {
- File fChild = new File(next, childname);
- stack.push(fChild.getAbsolutePath());
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment