Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.epam.automation.input.main;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- public class Program {
- public static void main(String[] args) throws FileNotFoundException {
- String path = "d:/Java/collections/collections/src/main/java/com/epam/automation/input/main";
- File file = new File(path);
- File fileForPrint = new File("d:/Java/collections/collections/src/main/java/com/epam/automation/input/main/structureFile");
- PrintWriter pw = new PrintWriter(fileForPrint);
- if (file.exists()) {
- if (file.isDirectory()) {
- pw.println(file.getName());
- writeStructure(file,pw,0);
- }
- }
- pw.close();
- }
- public static void writeStructure(File file,PrintWriter pw,int level) {
- File[] structure = file.listFiles();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < structure.length; i++) {
- if (structure[i].isDirectory()) {
- pw.println(("|---" + addSpaces(level,sb) + structure[i].getName()));
- writeStructure(structure[i],pw,level+1);
- } else {
- pw.println(("| " + structure[i].getName()));
- }
- }
- }
- public static StringBuilder addSpaces (int level,StringBuilder sb) {
- for (int i = 0; i < level; i++) {
- sb.append(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement