package com.itbuluoge.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class GetChannel {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {

/*文件内容拷贝*/
FileChannel fca=new FileInputStream("data.txt").getChannel();
FileChannel fcb=new FileOutputStream("back.txt").getChannel();

ByteBuffer swap=ByteBuffer.allocate(1000);
fca.read(swap);
while(swap.hasRemaining())
{
swap.flip();
/*写入到新文件*/
fcb.write(swap);
}
}

}