我正在编写程序部分只是为了将文件从源文件复制到目标文件.代码也可以正常运行,但是如果存在文件大文件,则在目标文件达到4.3 GB的大小之后,复制过程将结束,但有异常.例外情况是"文件大到"它看起来像:
java.io.IOException: Die Datei ist zu groß
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.FileDispatcherImpl.write(FileDispatcherImpl.java:60)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:211)
at java.nio.channels.Channels.writeFullyImpl(Channels.java:78)
at java.nio.channels.Channels.writeFully(Channels.java:101)
at java.nio.channels.Channels.access$000(Channels.java:61)
at java.nio.channels.Channels$1.write(Channels.java:174)
at java.nio.file.Files.copy(Files.java:2909)
at java.nio.file.Files.copy(Files.java:3069)
at sample.Controller.copyStream(Controller.java:318)
Run Code Online (Sandbox Code Playgroud)
产生的方法如下:
private void copyStream(File src, File dest){
try {
FileInputStream fis = new FileInputStream(src);
OutputStream newFos = java.nio.file.Files.newOutputStream(dest.toPath(),StandardOpenOption.WRITE);
Files.copy(src.toPath(),newFos);
newFos.flush();
newFos.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用java.io Fileoutputstream并以kbyte方式写入,但发生的情况相同.如何复制或创建大于4.3 GB的文件?是否可能用java以外的其他语言?这个程序我运行在Linux(Ubuntu LTS 16.04)上.
提前致谢.
编辑:
非常感谢大家的帮助.正如你所说,文件系统是问题所在.在我将文件系统格式化为exfat后,它工作正常.