Basically, my code works to get the necessary data in the right place but I am not initializing the correct objects to do it.
package com.codegym.task.task18.task1808;
/*
Splitting a file
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//Collect filenames
String file1 = br.readLine();
String file2 = br.readLine();
String file3 = br.readLine();
//Input stream initialized below
FileInputStream inputStream = new FileInputStream(file1);
//Collecting total number of bytes
int totalBytes = inputStream.available();
int halved = 0;
if (totalBytes % 2 == 0) {
halved = totalBytes / 2;
} else halved = (totalBytes / 2) +1;
FileOutputStream outputStream = new FileOutputStream(file2);
while (inputStream.available() > 0) {
//Add buffer and fill buffer to requirements
byte[] buffer = new byte[halved];
int data = inputStream.read(buffer);
outputStream.write(buffer, 0, data);
//Close file2 output stream and initialize file3 stream
outputStream.close();
outputStream = new FileOutputStream(file3);
}
br.close();
inputStream.close();
outputStream.close();
}
}