The file I used for testing created a byte[] of length 47, and the last index accessed through the "fos1.write(buffer,midle,(buffer.length - 1))" (exception thrown at line 16) is 46. I don't see where the error is coming from.
Thanks!(code below)
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try(FileInputStream fis = new FileInputStream(br.readLine());
FileOutputStream fos0 = new FileOutputStream(br.readLine());
FileOutputStream fos1 = new FileOutputStream(br.readLine())){
if(fis.available() > 0){
final int length = fis.available();
byte[] buffer = new byte[length];
fis.read(buffer);
int midle = 0 ;
if((buffer.length % 2) != 0){
midle = (buffer.length / 2);
fos0.write(buffer, 0,midle);
fos1.write(buffer,midle + 1,(buffer.length - 1));
}else {
midle = buffer.length / 2;
fos0.write(buffer,0,midle - 1);
fos1.write(buffer,midle + 1, buffer.length - 1);
}
}
}catch (IOException ioe){
}
}