Well first of all this whole theme is kinda difficult for me. The Problem here is that the programm times out while verfication and i dont know why. Would be nice if you have any tipps here. If you have any good articel about streams please let me know or other ideas to understand the theme better.
package de.codegym.task.task18.task1808;
/*
Eine Datei teilen
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
File file1 = new File(reader.readLine());
File file2 = new File(reader.readLine());
File file3 = new File(reader.readLine());
FileInputStream inStream = new FileInputStream(file1);
reader.close();
FileOutputStream outStream1 = new FileOutputStream(file2);
FileOutputStream outStream2 = new FileOutputStream(file3);
while (inStream.available() > 0){
if (file1.length() %2 == 0){
byte [] buffer1 = new byte [(int) file1.length()/2];
int count = inStream.read(buffer1);
outStream1.write(buffer1,0 ,count);
byte [] buffer2 = new byte [(int) file1.length()/2];
int count1= inStream.read(buffer2);
outStream2.write(buffer2,0 ,count1);
}else if (file1.length() %2 != 0 ){
byte [] buffer1 = new byte [(int) file1.length()/2+1];
int count = inStream.read(buffer1);
outStream1.write(buffer1,0 ,count);
byte [] buffer2 = new byte [(int) file1.length()/2];
int count1= inStream.read(buffer2);
outStream2.write(buffer2,0 ,count1);
}
}
inStream.close();
outStream1.close();
outStream2.close();
}
}