Where am I going wrong? public class Solution { public static void main(String[] args)throws IOException { //Read a file name three times from the console BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String file1 = reader.readLine(); String file2 = reader.readLine(); String file3 = reader.readLine(); //Use FileInputStream to read from a file FileInputStream inputStream = new FileInputStream(file1); byte[]buffer = new byte[inputStream.available()]; while(inputStream.available() > 0){ inputStream.read(buffer); } //Use FileOutputStream to write to files FileOutputStream outputStream2 = new FileOutputStream(file2); FileOutputStream outputStream3 = new FileOutputStream(file3); int bottomHalf = 0; int topHalf = 0; if(buffer.length % 2 != 0){ bottomHalf = (buffer.length + 1)/2 ; topHalf = bottomHalf + 1; //The first half of the bytes in the first file must be written to the second file outputStream2.write(buffer,0,bottomHalf); //The second half of the bytes in the first file must be written to the third file outputStream3.write(buffer, topHalf,buffer.length -1); } else{ //The first half of the bytes in the first file must be written to the second file outputStream2.write(buffer,0,buffer.length/2 ); //The second half of the bytes in the first file must be written to the third file outputStream3.write(buffer,buffer.length/2 + 1,buffer.length -1); } //FileInputStream and FileOutputStream must be closed inputStream.close(); outputStream2.close(); outputStream3.close(); } }