Не выполнены все требования задачи. Если я комментирую цикл и вставлю метод копирования с System.arraycopy, то не проходит валидацию почти по всем пунктам и пишет, что не закрыт первый поток для чтения. Почему так?
package com.javarush.task.task18.task1819;
/*
Объединение файлов
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader reader = null;
InputStream in1 =null;
InputStream in2 =null;
OutputStream out =null;
try {
reader = new BufferedReader(new InputStreamReader(System.in));
String f1 = reader.readLine();
String f2 = reader.readLine();
reader.close();
in1 = new FileInputStream(f1);
in2 = new FileInputStream(f2);
byte [] buf1 = new byte [in1.available()];
byte [] buf2 = new byte [in2.available()];
int count1 = in1.read(buf1);
int count2 = in2.read(buf2);
in1.close();
in2.close();
int j= 0;
byte [] BIG = new byte [in1.available()+in2.available()];
for (int i =0; i<(in1.available()+in2.available()); i++){
if (i<in2.available()) BIG[i]=buf2[i];
else { BIG[i]=buf1[j]; j++;}
}
//System.arraycopy(buf2, 0, BIG, 0, buf2.length);
//System.arraycopy(buf1, 0, BIG, buf2.length, buf1.length);
out = new FileOutputStream(f1);
out.write(BIG, 0, count1);
} catch (Exception e) {}
finally {
out.close();
}
}
}