Помогите разобраться.
Условие не больше, т.е. <= выполнено.
Для сортировки использую TreeMap.
Что я не учла?
package com.javarush.task.task31.task3101;
import java.io.*;
import java.util.*;
/*
Проход по дереву файлов
*/
public class Solution {
public static void main(String[] args) throws IOException {
File path = new File(args[0]);
File resultFileAbsolutePath = new File(args[1]);
File destination = new File(resultFileAbsolutePath.getParent() + "/allFilesContent.txt");
if (FileUtils.isExist(resultFileAbsolutePath)) {
FileUtils.renameFile(resultFileAbsolutePath, destination);
}
resultFileAbsolutePath = destination;
TreeMap<String, File> nameFiles = makeMapOfFiles(path, resultFileAbsolutePath);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(resultFileAbsolutePath)));
for (Map.Entry<String, File> pair: nameFiles.entrySet()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pair.getValue())));
while (reader.ready()){
String text = reader.readLine();
writer.write(text + " ");
}
reader.close();
writer.write("\r\n");
}
writer.close();
}
public static TreeMap<String, File> makeMapOfFiles(File path, File destination) {
TreeMap<String, File> nameFiles = new TreeMap<>();
for (File file : Objects.requireNonNull(path.listFiles())) {
if (file.getName().equals(destination.getName())) continue;
if (file.isDirectory()) {
nameFiles = makeMapOfFiles(file, destination);
}
else {
if (file.length() <= 50) {
nameFiles.put(file.getName(), file);
}
}
}
return nameFiles;
}
}