JDK-6822107 : Insufficient System Resources When Copying Large Files with NIO FileChannels
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6u13
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-03-25
  • Updated: 2010-04-26
  • Resolved: 2009-03-25
Related Reports
Duplicate :  
Relates :  
Description
J2SE Version (please include all output from java -version flag):
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

Does this problem occur on J2SE 5.0.x or 6.0?  Yes / No (pick one)
Yes

Operating System Configuration Information (be specific):
Client: Microsoft Windows XP [Version 5.1.2600]

Bug Description:
Insufficient System Resources When Copying Large Files with NIO FileChannels

This is a duplicate of bug 4938442 which was closed as not a defect.

This has been tested on many systems on completely different Networks and 
does not work on any of them.

Just retested using 1.6.0_13 and this problem still exists.

The problem can be reproduced when copying a file > 64 MB to a shared directory.
Example: On Win_XP machine copying jdk-6u13-windows-i586-p.exe as the file (about 74.9 MB) to a remote shared directory on a Linux server.

Test program:

import static java.lang.System.*;
import java.io.*;
import java.nio.channels.*;

public class Test {
  public static void main(String args[]) {
    File sourceFile = new File("c:/test.exe"); // some local file that is larger than 64 MB
    File destinationFile = new File("s:/test.exe"); // where  the destination is a shared directory on a remote machine
    if (destinationFile.exists()) {
      destinationFile.delete();
    }
    try {
      FileInputStream input = new FileInputStream(sourceFile);
      try {
        FileOutputStream output = new FileOutputStream(destinationFile);
        try {
          FileChannel inputChannel = input.getChannel();
          long size = inputChannel.size();
          if (size != inputChannel.transferTo(0, size, output.getChannel())) {
            throw new IOException("Incomplete Transfer");
          }
        }
        finally {
          output.close();
        }
      }
      finally {
        input.close();
      }
    }
    catch (IOException ex) {
      out.println(ex);
    }
  }
}

Comments
EVALUATION Please see the evaluation in 6431344. The solution is to transfer in smaller chunks. An alternative solution in jdk7 is to use the Path#copyTo method. This does a high performance file copy (and can optionally copy all the file attributes).
25-03-2009