Can anyone tell me what I did wrong ? Because if I test I am passing...
package com.codegym.task.task31.task3101;
/*
Iterating through a file tree
*/
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
public class Solution {
public static void main(String[] args) throws IOException {
File directory = new File(args[0]);
File resultFileAbsolutePath = new File(args[1]);
// File directory = new File("C:\\Users\\cuksi\\Desktop\\test");
// File resultFileAbsolutePath = new File("C:\\Users\\cuksi\\Desktop\\test\\rezultat.txt");
File destination = new File(resultFileAbsolutePath.getParent() + "/allFilesContent.txt");
if (FileUtils.isExist(destination)) {
FileUtils.deleteFile(destination);
}
FileUtils.renameFile(resultFileAbsolutePath,destination);
List<String> fileList = new ArrayList<>();
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
for (File fileSubDir : file.listFiles()) {
if (fileSubDir.length() <= 50) {
fileList.add(fileSubDir.getName());
}
}
} else {
if (file.length() <= 50 && !file.getName().equals("allFilesContent.txt")) {
fileList.add(file.getName());
}
}
}
Collections.sort(fileList);
StringBuilder sb = new StringBuilder();
for (String name : fileList) {
sb.append(name + "\n");
}
sb.setLength(sb.length()-1);
FileOutputStream outputStream = new FileOutputStream(destination);
outputStream.write(sb.toString().getBytes());
outputStream.close();
}
}