Created
October 22, 2017 21:57
-
-
Save chaixdev/c5378ceeb3892311ece0e26036131b64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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