I used an if statement and not a while loop because I tried to read a write the half of bytes as a block !
package de.codegym.task.task18.task1808;
/*
Eine Datei teilen
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = reader.readLine();
//file2 w file3 ferghin lezem ykounou wala deja m3ebin na9ra mehom ?
String fileName2 = reader.readLine();
String fileName3 = reader.readLine();
FileInputStream fileInputStream = new FileInputStream(fileName1);
FileOutputStream fileOutputStream2 = new FileOutputStream(fileName2);
FileOutputStream fileOutputStream3 = new FileOutputStream(fileName2);
if ( fileInputStream.available()% 2 == 0) {
if (fileInputStream.available()/2 >0){
byte [] buffer = new byte [fileInputStream.available()/2 ];
int count = fileInputStream.read(buffer);
fileOutputStream2.write(buffer , 0 , count);
}
if (fileInputStream.available() > 0){
byte [] buffer = new byte [fileInputStream.available()];
int count = fileInputStream.read(buffer);
fileOutputStream3.write(buffer , 0 , count);
}
} else {
if (fileInputStream.available()/2 +1 >0){
byte [] buffer = new byte [fileInputStream.available()/2 ];
int count = fileInputStream.read(buffer);
fileOutputStream2.write(buffer , 0 , count);
}
if (fileInputStream.available() > 0){
byte [] buffer = new byte [fileInputStream.available()];
int count = fileInputStream.read(buffer);
fileOutputStream3.write(buffer , 0 , count);
}
}
fileInputStream.close();
fileOutputStream2.close();
fileOutputStream3.close();
}
}