Skip to content

Instantly share code, notes, and snippets.

@chaixdev
Created October 22, 2017 21:57
Show Gist options
  • Save chaixdev/c5378ceeb3892311ece0e26036131b64 to your computer and use it in GitHub Desktop.
Save chaixdev/c5378ceeb3892311ece0e26036131b64 to your computer and use it in GitHub Desktop.
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]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment