Пробывал закрывать через autoclosable в try-catch, пробовал прописывать закрытие в ручную в блоке finally, пробовал тупо пробросить исключение через мэйн и закрыть потоки самым проостым способом, но ничего не помогает, скиньте плиз в лс рабочее решение, и я пойду дальше, не хочу впустую тратить на это время.
package com.javarush.task.task18.task1818;
/*
Два в одном
*/
import java.io.*;
public class Solution {
private static File file1;
private static File file2;
private static File file3;
static {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in))) {
file1 = new File(bufferedReader.readLine());
file2 = new File(bufferedReader.readLine());
file3 = new File(bufferedReader.readLine());
} catch (IOException ex) {
}
}
public static void main(String[] args) throws FileNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] data = new byte[512];
int amountOfActualBytes;
FileInputStream fileInputStream = new FileInputStream(file2);
try {
while ((amountOfActualBytes = fileInputStream.read(data)) > 0) {
baos.write(data, 0, amountOfActualBytes);
}
} catch (IOException ex) {
} finally {
closer(fileInputStream, null);
}
FileInputStream fileInputStream_01 = new FileInputStream(file3);
try {
while ((amountOfActualBytes = fileInputStream_01.read(data)) > 0) {
baos.write(data, 0, amountOfActualBytes);
}
} catch (IOException ex) {
} finally {
closer(fileInputStream_01, null);
}
try (FileOutputStream fileOutputStream = new FileOutputStream(file1)) {
fileOutputStream.write(baos.toByteArray());
} catch (IOException ex) {
}
}
private static void closer(FileInputStream fis, FileOutputStream fos) {
if(fis != null){
try {
fis.close();
} catch (IOException ex){}
} else if(fos != null){
try {
fos.close();
} catch (IOException ex){}
}
}
}