Here is how I put a string to ByteBuffer
String message="Hello\n\n";
ByteBuffer bresult = ByteBuffer.allocate(message.getBytes().length);
bresult.put(message.getBytes());
bresult.flip();
When I convert bytebuffer to string to see the result \n\n is removed from the above string. This how I convert ByteBuffer to String
print(new String(bresult.array()));
and the result is Hello without any line breaks. You can see the result in the below screenshot from my log [![enter image description here][1]][1]
but when I add spaces to hello string like message="Hello\n\n " the result is the below: [![enter image description here][2]][2] as you can see there are some line breaks under hello string.