I think my solution is correct.
package pl.codegym.task.task18.task1825;
import com.sun.org.apache.xpath.internal.objects.XString;
import java.io.*;
import java.util.*;
/*
Tworzenie pliku
*/
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> nazwy = new ArrayList<>();
while (true) {
String nazwa = bufferedReader.readLine();
if (!nazwa.equals("end")){
nazwy.add(nazwa);
}else break;
}
bufferedReader.close();
Collections.sort(nazwy);
String nazwaDoFolderu = nazwy.get(0);
String [] robocze = nazwaDoFolderu.split("\\.part");
String nazwaGlowna = robocze[0] + ".";
FileOutputStream fileOutputStream = new FileOutputStream(nazwaGlowna, true);
for (String s : nazwy ){
FileInputStream fileInputStream = new FileInputStream(s);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
int i;
while((i = bufferedInputStream.read())!= -1){
fileOutputStream.write(i);
}
fileInputStream.close();
bufferedInputStream.close();
}
fileOutputStream.close();
}
}