Уходит в таймут, не могу понять почему
package com.javarush.task.task18.task1825;
import java.io.*;
import java.util.*;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String infile = reader.readLine();
ArrayList<String> list = new ArrayList<>();
while (!(infile.equals("end"))) {
list.add(infile);
}
reader.close();
Collections.sort(list);
FileOutputStream out = new FileOutputStream(list.get(0).substring(0, list.get(0).lastIndexOf(".")));
for (String s : list) {
FileInputStream fis = new FileInputStream(s);
byte[] arr = new byte[fis.read()];
while (fis.available() > 0) {
int data = fis.read(arr);
out.write(data);
}
fis.close();
out.close();
}
}
}