По факту программа прекрасно работает и в IDE и в виде .jar-а. Да и где я не закрыл поток, найти я так и не смог.
package com.javarush.task.task18.task1825;
import java.io.*;
import java.util.Comparator;
//import java.util.Set;
import java.util.TreeSet;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
FilesConcatination concat = new FilesConcatination();
String fileName = "";
while (true) {
try {
fileName = console.readLine();
} catch (IOException e) {
System.out.println("неверное имя файла" + e.getMessage());
}
if (fileName.equals("end")) break;
concat.add(fileName);
}
try {
console.close();
concat.mergeIn1();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class FilesConcatination {
TreeSet<String> partsList = new TreeSet<>(new CompareExtension());
void add(String fname) {
this.partsList.add(fname);
}
void mergeIn1() throws IOException {
FileOutputStream fileCombined = new FileOutputStream(partsList.first().substring(
0, partsList.first().lastIndexOf(".")));
FileInputStream sourceFile;
for (String file : partsList) {
sourceFile = new FileInputStream(file);
int i = sourceFile.available();
byte[] b = new byte[i];
sourceFile.read(b,0, i);
fileCombined.write(b, 0, i);
fileCombined.flush();
sourceFile.close();
}
fileCombined.close();
}
static class CompareExtension implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
String cmpO1 = o1.substring(o1.lastIndexOf(".") + 5);
String cmpO2 = o2.substring(o2.lastIndexOf(".") + 5);
if (Integer.parseInt(cmpO1) > Integer.parseInt(cmpO2)) return 1;
else if (Integer.parseInt(cmpO1) < Integer.parseInt(cmpO2)) return -1;
return 0;
}
}
}