Code Used in the Program
public static void main(String args[]) throws IOException
{
FileInputStream input = new FileInputStream ("D:\\testin.txt");
ReadableByteChannel source = input.getChannel();
FileOutputStream output = new FileOutputStream ("D:\\testout.txt");
WritableByteChannel destination = output.getChannel();
copyData(source, destination);
source.close();
destination.close();
}
private static void copyData(ReadableByteChannel src, WritableByteChannel dest) throws IOException
{
ByteBuffer buffer = ByteBuffer.allocateDirect(20 * 1024);
while (src.read(buffer) != -1)
{
buffer.flip();
while (buffer.hasRemaining())
{
dest.write(buffer);
}
buffer.clear();
System.out.println("Close");
}
}