FileChannelCopy.java

import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FileChannelCopy {
  public static void main(String[] args) throws IOException {
    FileInputStream in = new FileInputStream(args[0]);
    FileChannel cin = (FileChannel)in.getChannel();
    FileOutputStream out = new FileOutputStream(args[1]);
    FileChannel cout = out.getChannel();
    ByteBuffer byteB = ByteBuffer.allocateDirect(1000);
    int result;
    try {
      while((result=cin.read(byteB))!=-1) {
    byteB.flip();  // position=0, limite=fin données lues          
    cout.write(byteB);      
    byteB.clear(); // position=0, limite=capacité
      }
    } finally {
      cin.close();     // Ferme le canal et le flot !
      cout.close();
    }
  }
}