package org.demo;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class Demo {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileInputStream fis=new FileInputStream("D:\\cc.MP4");
FileOutputStream fos=new FileOutputStream("D:\\Copycc.MP4");
FileChannel ic=fis.getChannel();
FileChannel oc=fos.getChannel();
ByteBuffer bf=ByteBuffer.allocateDirect(52428800);
while (true) {
bf.clear();
int num=ic.read(bf);
if (num<0) {
break;
}
bf.flip();
oc.write(bf);
}
System.out.println("下载成功");
}
}
|