java流与缓冲区

如果不用BufferedOutputStream缓冲,每一次write都会立即发送。

DataOutputStream outstream =new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));

outstream .writeInt();

outstream .writeInt();

outstream .flush();

ByteBuffer bytebuffer= ByteBuffer.allocate(1024);

byte[] buffer=bytebuffer.bytes();

socket.getOutputStream().write(buffer, offset, count);

 

注意readChar 读入16位。java的Char16位

你可能感兴趣的:(java流与缓冲区)