[英]Java java.nio writes line of []s
I am using java.nio to copy a file, it copies fine except for the fact that there is a line of []s at the end of the file. 我正在使用java.nio复制文件,除了文件末尾有[]一行以外,它复制得很好。
Here is my code: 这是我的代码:
source (the source channel)
source.read(buffer);
buffer.flip();
mbb.put(buffer)
mbb is MappedByteBuffer
Source Channel: 来源频道:
source = new FileInputStream(original(this is a File)).getChannel();
MappedByteBuffer: MappedByteBuffer:
source.map(FileChannel.MapMode.READ_WRITE, 0, 1024);
You are assuming the file is 1024 bytes long instead of using the actual file size. 您假设文件的长度为1024字节,而不是使用实际的文件大小。 I suspect the junk is in the MappedByteBuffer rather than the file.
我怀疑垃圾在MappedByteBuffer中而不是文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.