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);
- }
- else {
- }
- }
- pw.close();
- }
- public static void writeStructure(File file, PrintWriter pw, int level) {
- File[] structure = file.listFiles();
- StringBuilder sb = new StringBuilder();
- String spaces = addSpaces(level, sb).toString();
- for (int i = 0; i < structure.length; i++) {
- if (structure[i].isDirectory()) {
- pw.println(spaces + "|---" + structure[i].getName());
- writeStructure(structure[i], pw, level + 1);
- } else {
- pw.println(spaces + "| " + sb + structure[i].getName());
- }
- }
- }
- public static StringBuilder addSpaces(int level, StringBuilder sb) {
- for (int i = 0; i < level * 4; i++) {
- sb.append(" ");
- }
- return sb;
- }
- public static void readFile () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement