Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package com.epam.automation.input.main;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.PrintWriter;
  6.  
  7. public class Program {
  8. public static void main(String[] args) throws FileNotFoundException {
  9. String path = "d:/Java/collections/collections/src/main/java/com/epam/automation/input/main";
  10. File file = new File(path);
  11. File fileForPrint = new File("d:/Java/collections/collections/src/main/java/com/epam/automation/input/main/structureFile");
  12. PrintWriter pw = new PrintWriter(fileForPrint);
  13. if (file.exists()) {
  14. if (file.isDirectory()) {
  15. pw.println(file.getName());
  16. writeStructure(file,pw,0);
  17. }
  18. }
  19. pw.close();
  20. }
  21.  
  22. public static void writeStructure(File file,PrintWriter pw,int level) {
  23. File[] structure = file.listFiles();
  24. StringBuilder sb = new StringBuilder();
  25. for (int i = 0; i < structure.length; i++) {
  26. if (structure[i].isDirectory()) {
  27. pw.println(("|---" + addSpaces(level,sb) + structure[i].getName()));
  28. writeStructure(structure[i],pw,level+1);
  29. } else {
  30. pw.println(("| " + structure[i].getName()));
  31. }
  32. }
  33. }
  34. public static StringBuilder addSpaces (int level,StringBuilder sb) {
  35. for (int i = 0; i < level; i++) {
  36. sb.append(" ");
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement