Валидатор не пропускает. На тестовых файлах все работает
package com.javarush.task.task31.task3101;
import java.io.*;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
/*
Проход по дереву файлов
*/
public class Solution {
public static void main(String[] args) {
final String allFilesName = "allFilesContent.txt";
File path = new File(args[0]);
File resultFileAbsolutePath = new File(args[1]);
// File path = new File("c:/1test/txt");
// File resultFileAbsolutePath = new File("c:/1test/123.txt");
File newAllFile = new File(resultFileAbsolutePath.getParent() + "/" + allFilesName);
FileUtils.renameFile(resultFileAbsolutePath, newAllFile);
SortedMap<String, File> result = checkDir(path);
// System.out.println(result);
StringBuffer allText = new StringBuffer();
for (Map.Entry pair : result.entrySet()
) {
try (BufferedInputStream is = new BufferedInputStream(new FileInputStream((File) pair.getValue()))) {
byte[] buffer = new byte[is.available()];
is.read(buffer);
allText.append(new String(buffer) + "\n");
// System.out.println(allText);
} catch (IOException e) {
e.printStackTrace();
}
}
try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(newAllFile));
) {
String temp = allText.substring(0, allText.length() - 1);
os.write(temp.getBytes());
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
static SortedMap<String, File> checkDir(File path) {
SortedMap<String, File> result = new TreeMap<>();
for (File file : path.listFiles()) {
if (file.isDirectory()) {
result.putAll(checkDir(file));
} else if (file.length() < 51 && file.getName().endsWith(".txt")) {
result.put(file.getName(), file);
}
}
return result;
}
}