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.
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:
source.map(FileChannel.MapMode.READ_WRITE, 0, 1024);
You are assuming the file is 1024 bytes long instead of using the actual file size. I suspect the junk is in the MappedByteBuffer rather than the file.