解决方案 »

  1.   

      不知道,可能是flip和compact的问题,要怎么写才正确啊。
      

  2.   

    原来是这样
    public static void main(String[] args) throws IOException {
    FileInputStream inFile = new FileInputStream("C:/Documents and Settings/Administrator/桌面/qq.docx");
    FileOutputStream outFile = new FileOutputStream("C:/Documents and Settings/Administrator/桌面/oo.docx");

    FileChannel inChannel = inFile.getChannel();
    FileChannel outChannel = outFile.getChannel();
    ByteBuffer buffer = ByteBuffer.allocate(1024*1024);
    int bytesRead = 0;
    while(bytesRead >=0 ){
    if(bytesRead != -1) bytesRead = inChannel.read(buffer);
    buffer.flip();
    outChannel.write(buffer);
    buffer.compact();    //position = n+1; limit = capacity
    }
    buffer.flip();
    while(buffer.hasRemaining())    //position < limit
    outChannel.write(buffer);

    inFile.close();
    outFile.close();
    }