Guest User

Untitled

a guest
Oct 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package util;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import Printer.Printer;
  7.  
  8. public class TreePrint {
  9. private Printer printer;
  10.  
  11. public TreePrint(Printer p) {
  12. this.printer = p;
  13. }
  14.  
  15. public void treePrint(String s) throws IOException{
  16. File file = new File(s);
  17. recursivePrint(1, file);
  18. }
  19. public void recursivePrint(int indent, File file) throws IOException {
  20. for (int i = 0; i < indent; i++) {
  21. printer.print("-");
  22. }
  23. printer.println(file.getName());
  24. if (file.isDirectory()) {
  25. File[] files = file.listFiles();
  26. for (int i = 0; i < files.length; i++)
  27. recursivePrint(indent + 4, files[i]);
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment