demo:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class TestDemo1 {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("a.txt");
FileOutputStream fileOutputStream = new FileOutputStream("b.txt");
//获取各个流对应的channel
FileChannel sourceCh =fileInputStream.getChannel();
FileChannel destCh = fileOutputStream.getChannel();
//使用transferFrom完成拷贝
destCh.transferFrom(sourceCh,0,sourceCh.size());
//关闭通道和流
sourceCh.close();
destCh.close();
fileInputStream.close();
fileOutputStream.close();
}
}