Все же задам, если сам не смогу разобраться раньше:
Валидатор не принимает решение по 3му пункту, результат при тестировании совпадает с ожидаемым.
package com.javarush.task.task31.task3101;
import java.io.*;
import java.util.*;
/*
Проход по дереву файлов
*/
public class Solution {
public static void main(String[] args) {
File path = new File(args[0]);
File result = new File(args[1]);
File resultFileAbsolutePath = new File(result.getParent() + "/allFilesContent.txt");
List<File> list = new ArrayList<>();
search(path, list, 50);
Collections.sort(list, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
if (FileUtils.isExist(resultFileAbsolutePath))
FileUtils.deleteFile(resultFileAbsolutePath);
FileUtils.renameFile(result, resultFileAbsolutePath);
try{
searchAndWrite(list, resultFileAbsolutePath);
} catch (FileNotFoundException e){
System.out.println("Not found");
} catch (IOException e) {
System.out.println("IOException");
}
}
public static void search(File path, List<File> map, int size) {
for(File file : path.listFiles()){
if (file.isDirectory()){
search(file, map, size);
}
else {
if(file.getName().endsWith(".txt")&&file.length() <=size) {
map.add(file);
}
}
}
}
public static void searchAndWrite(List<File> list, File result) throws FileNotFoundException, IOException {
try (FileOutputStream out = new FileOutputStream(result)) {
int count = 0;
for(File file : list){
if(count !=0 ) {
out.write("\r\n".getBytes());
}
FileInputStream in = new FileInputStream(file);
count = 1;
while (in.available() > 0) {
int read = in.read();
out.write(read);
}
in.close();
}
}
}
}