I think my code is sequentially correct, but I might misunderstand the reading of bytes ?
package com.codegym.task.task18.task1808;
/*
Splitting a file
*/
import java.io.*;
public class Solution {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String f1 = "",f2="",f3="";
long counter = 0,halfLength = 0;
try{
f1 = reader.readLine();
f2 = reader.readLine();
f3 = reader.readLine();
FileInputStream inStream = new FileInputStream(f1);
FileOutputStream outStream1 = new FileOutputStream(f2);
FileOutputStream outStream2 = new FileOutputStream(f3);
File inFile = new File(f1);
long fileLength = inFile.length();
if ((fileLength % 2)==0){
//filelength is even number
//divide length by 2 to know when to start to write to second file
halfLength = (fileLength /2);
long i = 0;
while (inStream.available()>0){
for (i = 0;i< halfLength;i++){
int n = inStream.read();
outStream1.write(n);
}
while (inStream.available()>0){
int n = inStream.read();
outStream2.write(n);
}
}
}
else{
halfLength = (fileLength /2);
halfLength --;
long i = 0;
while (inStream.available()>0){
for (i = 0;i< halfLength;i++){
int n = inStream.read();
outStream1.write(n);
}
while (inStream.available()>0){
int n = inStream.read();
outStream2.write(n);
}
}
}
reader.close();
inStream.close();
outStream1.close();
outStream2.close();
}
catch (Exception e){
}
}
}