import java.nio.*;
import java.io.*;
import java.nio.channels.*;public class FileTest
{
public static void main(String[] args) throws IOException
{
FileChannel out=new FileOutputStream("data3.txt").getChannel();
ByteBuffer bb=ByteBuffer.allocate(1024);
bb.asCharBuffer().put("hahahaha");
out.position(in.size());
out.write(bb);
bb.flip();
out.position(in.size());
bb.clear();
bb.asCharBuffer().put("I love you");
out.write(bb);
bb.flip();
out.close();
}
}最后data3.txt输出为 I l o v e y o u ,没错,有空格;而我想要的结果是hahaha,I love you.
为什么会是这个结果?