Code is working fine in Eclipse, but not working here..
package com.codegym.task.task18.task1808;
import java.io.*;
import java.util.*;
/*
Splitting a file
Requirements:
1. The program should read a file name three times from the console.
2. Use FileInputStream to read from a file, and use FileOutputStream to write to files.
3. The first half of the bytes in the first file must be written to the second file.
4. The second half of the bytes in the first file must be written to the third file.
5. The FileInputStream and FileOutputStream must be closed.
*/
public class Solution {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String filename1 = reader.readLine();
String filename2 = reader.readLine();
String filename3 = reader.readLine();
FileInputStream input = new FileInputStream(filename1);
FileOutputStream output1 = new FileOutputStream(filename2);
FileOutputStream output2 = new FileOutputStream(filename3);
int length = input.available();
int half = length/2;
if(length % 2 == 0) {
byte[] buffer = new byte[half];
int data = input.read(buffer,0,half);
output1.write(buffer,0, data);
int data2 ;
while((data2 = input.read()) != -1) {
output2.write(data2);
}
}else {
byte[] buffer = new byte[half];
int data = input.read(buffer,0,half);
output2.write(buffer,0, data);
int data2 ;
while((data2 = input.read()) != -1) {
output1.write(data2);
}
}
input.close();
output1.close();
output2.close();
}catch(Exception ex){
}
}
}