java – 复制文件时出现无提示错误

我有以下复制文件的方法:

public static void nioCopy(File source, File destination) {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    FileChannel input = null;
    FileChannel output = null;
    try {
        fis = new FileInputStream(source);
        fos = new FileOutputStream(destination);

         input = fis.getChannel();
         output = fos.getChannel();

        input.transferTo(0, input.size(), output);

    } catch (FileNotFoundException ex) {
        Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, "Can't find either of input/output files.", ex);
    } catch (IOException ex) {
        Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, "Can't open either of input/output file for reading/writing", ex);
    } finally {
        try {
            fis.close();
            fos.close();
            input.close();
            output.close();
        } catch (IOException ex) {
            Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, "Error closing streams", ex);
        }

    }
}

我正在使用复制文件但有时我得到一个无声错误或未定义的行为,或者我只是不知道如何解释它,这就是我得到的:

这是我的来源:

-rw-r--r-- 1 nb9 team92 3.1G 2011-10-13 16:31 6443_6#5_1_6443_6#5_2.fastq.f.fq.gz

这是目的地:

-rw-r--r-- 1 nb9 team92 2.0G 2011-10-13 16:49 6443_6#5_1_6443_6#5_2.fastq.f.fq.gz

在执行此过程时我没有异常,并且通过它的外观一切都应该成功但是当我开始解压缩文件时,我得到:

java.io.EOFException:ZLIB输入流的意外结束

显然目的地是原始标记1 gig.

唯一的特点是两个文件都在非常繁忙的光泽文件系统上,这有可能是一些有趣的东西吗?

最佳答案 在2Gb被截断的事实让我怀疑.我搜索它看起来像
issue with nio.它也可能是目标文件系统允许最大2Gb文件.

Java NIO: Buffers开始

At present, buffer sizes are limited to 2GB (the maximum positive number that can be represented in an int. An updated planned for Java 7 will allow large buffers (with the size and indexes held as a long).

无论如何,只是为了确定:

>如果你有空间,你可以尝试在同一个文件系统上复制它吗?
>您可以尝试使用Apache Commons IO FileUtils.copyFile()吗?似乎他们fixed this issue.
>如果您可以升级,请尝试使用Java 7,因为已经出来了

点赞