private static void doCopyFile(File source, File target) throws IOException {

    try (FileInputStream in = new FileInputStream(source);
         FileOutputStream out = new FileOutputStream(target)) {
      // instead of checking transferred size, we'll compare file sizes in checkSameSize()
      in.getChannel().transferTo(0, Long.MAX_VALUE, out.getChannel());
    }
  }
Returns the text read from the given stream as a String.
Closes the given stream upon return.
spock-core/src/main/java/org/spockframework/util/IoUtil.java