File filePath = new File(args[0]);
File resultAbsolutePath = new File(args[1]);
File destination = new File(resultAbsolutePath.getParent() + "/allFilesContent.txt");
FileUtils.renameFile(resultAbsolutePath, destination);
ArrayList<File> fileList = getFileList(filePath);
FileOutputStream out = new FileOutputStream(destination);
Collections.sort(fileList);
for(int i = 0; i < fileList.size(); i++){
FileInputStream stream = new FileInputStream(fileList.get(i));
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String str;
while((str = reader.readLine()) != null){
str += str;
}
stream.close();
reader.close();
out.write((str + "\n").getBytes());
out.flush();
}
out.close();
}
public static ArrayList<File> getFileList(File path) {
ArrayList<File> list = new ArrayList<>();
for (File file : path.listFiles()) {
if (file.isDirectory()) {
ArrayList<File> proxyFileList = getFileList(file);
list.addAll(proxyFileList);
} else if (file.length() <= 50) {
list.add(file);
}
}
String str;
while((str = reader.readLine()) != null){
str += str;
}
String resultStr;
String line;
while((line = reader.readLine()) != null){
resultStr += line;
}
String resultStr = String.join("\n", Files.readAllLines(file.toPath()));