Не наблюдаю открытых потоков, может кто-то более зрячий?
package com.javarush.task.task18.task1808;
/*
Разделение файла
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
String[] fileNames = new String[3];
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<fileNames.length; i++){
fileNames[i] = reader.readLine();
}
FileInputStream fileInputStream = new FileInputStream(fileNames[0]);
int secondFileBlockSize = 0;
int thirdFileBlockSize = 0;
if(fileInputStream.available()%2!=0){
secondFileBlockSize = fileInputStream.available()/2+1;
thirdFileBlockSize = fileInputStream.available() - secondFileBlockSize;
} else {
secondFileBlockSize = fileInputStream.available()/2;
thirdFileBlockSize = fileInputStream.available() - secondFileBlockSize;
}
byte[] secondFileBlock = new byte[secondFileBlockSize];
byte[] thirdFileBlock = new byte[thirdFileBlockSize];
fileInputStream.read(secondFileBlock);
fileInputStream.read(thirdFileBlock);
reader.close();
fileInputStream.close();
FileOutputStream fileOutputStream = new FileOutputStream(fileNames[1]);
fileOutputStream.write(secondFileBlock,0,secondFileBlockSize);
fileInputStream.close();
FileOutputStream fileOutputStream1 = new FileOutputStream(fileNames[2]);
fileOutputStream1.write(thirdFileBlock,0,thirdFileBlockSize);
fileOutputStream1.close();
}
}