import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.util.Arrays;
public class t2 {
public static final int BUFSIZE=1024*8;
public static void main(String[] args) {
// TODO Auto-generated method stub
String bigs="F://bigs.txt";
String[] files=new String[] {
"F:/1.txt","F:/2.txt","F:/3.txt"
};
FileChannel outChannel=null;
try {
outChannel=new FileOutputStream(bigs).getChannel();
for(String f:files) {
Charset charset=Charset.forName("utf-8");
CharsetDecoder chdecoder=charset.newDecoder();
CharsetEncoder chencoder=charset.newEncoder();
FileChannel fc=new FileInputStream(f).getChannel();
ByteBuffer bb=ByteBuffer.allocate(BUFSIZE);
CharBuffer charBuffer=chdecoder.decode(bb);
ByteBuffer nbuBuffer=chencoder.encode(charBuffer);
while(fc.read(nbuBuffer)!=-1) {
bb.flip();
nbuBuffer.flip();
outChannel.write(nbuBuffer);
bb.clear();
nbuBuffer.clear();
}
fc.close();
}
}catch(IOException ioe) {
ioe.printStackTrace();
}finally {
try {
if(outChannel!=null) {
outChannel.close();
}
}catch(IOException ignore) {}
}
}
}