I am converting a String to byte[] and then again byte[] to String in java using the getbytes() and String constructor,
String message = "Hello World";
byte[] message1 = message.getbytes();
using PipedInput/OutputStream I send this to another thread, where,
byte[] getit = new byte[1000];
pipedinputstream.read(getit);
print(new String(getit));
This last print result in 1000 to be printed… I want the actual string length. How can i do that?
When reading the String, you need to get the number of bytes read, and give the length to your String:
Note that if your String is longer than 1000 bytes, it will be truncated.