File Java Tutorial

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
public class MainClass {
  public static void main(String[] args) throws Exception {
    File fromFile = new File("fromFile.txt");
    File toFile = new File("toFile.txt");
    FileInputStream inFile = new FileInputStream(fromFile);
    FileOutputStream outFile = new FileOutputStream(toFile);
    FileChannel inChannel = inFile.getChannel();
    FileChannel outChannel = outFile.getChannel();
    int bytesWritten = 0;
    long byteCount = inChannel.size();
    while (bytesWritten < byteCount) {
      bytesWritten += inChannel.transferTo(bytesWritten, byteCount - bytesWritten, outChannel);
    }
    inFile.close();
    outFile.close();
  }
}