64,646
社区成员
发帖
与我相关
我的任务
分享
String contents="test";
IoBuffer buffer = IoBuffer.allocate( 4 + contents.length, false);
//buffer.order(ByteOrder.BIG_ENDIAN);
buffer.putInt(contents.length); //java里面int占4个字节,存放contents的长度
buffer.put(content.getBytes());
byte[] contents = content.getBytes(Charset.forName("UTF-8"));
IoBuffer buffer = IoBuffer.allocate( 4 + contents.length, false);
//buffer.order(ByteOrder.BIG_ENDIAN);
buffer.putInt(contents.length);
buffer.put(content.getBytes());
buffer.flip();
out.write(buffer);