Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package util;
- import java.io.File;
- import java.io.IOException;
- import Printer.Printer;
- public class TreePrint {
- private Printer printer;
- public TreePrint(Printer p) {
- this.printer = p;
- }
- public void treePrint(String s) throws IOException{
- File file = new File(s);
- recursivePrint(1, file);
- }
- public void recursivePrint(int indent, File file) throws IOException {
- for (int i = 0; i < indent; i++) {
- printer.print("-");
- }
- printer.println(file.getName());
- if (file.isDirectory()) {
- File[] files = file.listFiles();
- for (int i = 0; i < files.length; i++)
- recursivePrint(indent + 4, files[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment