Тестирую, пишет как надо вроде...
package com.javarush.task.task31.task3101;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Проход по дереву файлов
*/
public class Solution {
public static void main(String[] args) {
File path = new File(args[0]);
// System.out.println(path.getName());
File resultFileAbsolutePath = new File(args[1]);
File rename = new File(resultFileAbsolutePath.getParent() + "\\allFilesContent.txt");
// System.out.println(resultFileAbsolutePath.getParent() + "\\allFilesContent.txt");
if (FileUtils.isExist(resultFileAbsolutePath)) {
FileUtils.renameFile(resultFileAbsolutePath, rename);
}
ArrayList<String> fileList = new ArrayList<>();
try {
for (File file : path.listFiles()) {
if (file.length() < 50 && file.getName().endsWith(".txt")) {
fileList.add(file.getName());
// System.out.println(file.getName());
}
}
} catch (NullPointerException e) {
System.out.println("Null");
}
Collections.sort(fileList);
try (FileOutputStream fos = new FileOutputStream(rename)) {
FileInputStream fis = null;
BufferedReader br = null;
for (String filename : fileList) {
fis = new FileInputStream(path + "\\" + filename);
br = new BufferedReader(new InputStreamReader(fis));
StringBuilder sb = new StringBuilder();
String line = null;
while (br.ready()) {
sb.append(br.readLine());
}
fos.write(sb.toString().getBytes());
fos.write(("\n").getBytes());
}
fis.close();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}