byte[] buffer = new byte[1000];
while (inputStream.available() > 0) //as long as there are unread bytes
{
//Read the next block of bytes into buffer, and store the actual number of bytes read in count.
int count = inputStream.read(buffer);
outputStream.write(buffer, 0, count/2);
outputStream1.write(buffer, (count-1)/2, count);}//Write a block (part of a block) to the second stream
inputStream.close(); //Close both streams. We don't need them any more.
outputStream.close();
outputStream1.close();
}
package com.codegym.task.task18.task1808;
/*
Splitting a file
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception
{
//Create a stream to read bytes from a file
Scanner in = new Scanner(System.in);
System.out.println("enter file1 name");
String file1=in.nextLine();
System.out.println("enter file1 name");
String file2=in.nextLine();
System.out.println("enter file3 name");
String file3=in.nextLine();
FileInputStream inputStream = new FileInputStream(file1);
//Create a stream to write bytes to a file
FileOutputStream outputStream = new FileOutputStream(file2);
FileOutputStream outputStream1 = new FileOutputStream(file3);
byte[] buffer = new byte[1000];
while (inputStream.available() > 0) //as long as there are unread bytes
{
//Read the next block of bytes into buffer, and store the actual number of bytes read in count.
int count = inputStream.read(buffer);
outputStream.write(buffer, 0, count/2);
outputStream1.write(buffer, (count-1)/2, count);}//Write a block (part of a block) to the second stream
inputStream.close(); //Close both streams. We don't need them any more.
outputStream.close();
outputStream1.close();
}
}