Проверяю по коду все работает, что я не учел
package com.javarush.task.task18.task1825;
/*
Собираем файл
*/
import java.io.*;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
LinkedList<String> file = new LinkedList<>();
Scanner sc = new Scanner(System.in);
String superfilename =null;
while (true){
String filename = sc.nextLine();
if(filename.equals("end")){
break;
}
if (superfilename==null){
superfilename = filename.substring(0,filename.indexOf(".part")+1);
}
file.add(filename);
}
Collections.sort(file);
sc.close();
File file1 = new File(superfilename);
FileOutputStream fileOutputStream = new FileOutputStream(file1);
for (String str : file){
FileInputStream fileInputStream = new FileInputStream(str);
try {
byte[] buffer = new byte[fileInputStream.available()];
fileInputStream.read(buffer);
fileOutputStream.write(buffer);
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}