Keep getting the following mentor recommendation:
When there is an odd number of bytes in the first file, your program writes the smaller half of the bytes. It should write the larger half.
When there is an odd number of bytes in the first file, your program writes the larger half to the third file. It should write the smaller half.
I've tried all combinations of +1/-1/+2 etc in lines 29/30 and 32/33 - nothing works
package com.codegym.task.task18.task1808;
import java.io.*;
/*
Splitting a file
*/
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
String file3 = reader.readLine();
FileInputStream fileReader1 = new FileInputStream(file1);
FileOutputStream fileWriter2 = new FileOutputStream(file2);
FileOutputStream fileWriter3 = new FileOutputStream(file3);
byte[] buffer = new byte[fileReader1.available()];
int count = 0;
while (fileReader1.available()>0){
count += fileReader1.read(buffer);
}
if (count%2==0){
fileWriter2.write(buffer,0,(count/2)-1);
fileWriter3.write(buffer,((count/2)),count);
}else{
fileWriter2.write(buffer,0,((count/2)+1));
fileWriter3.write(buffer,((count/2)+2),count);
}
fileReader1.close();
fileWriter2.close();
fileWriter3.close();
}
}