byte to string conversion creates problem in streams
I am reading bytes from InputStream and converting these bytes read to the string .After that I am writing bytes to the Output Stream.
Following is the code-
However I am not getting the expected output.
byte b = new byte ;
int len = inputStream.read(b);
String s = new String( b );
outputStream.write(s.getBytes(), 0 , len);
May I know if I am doing any mistake in these string to byte conversion?
Re: byte to string conversion creates problem in streams
When you say
you are creating a string of length 16384, regardless of how many bytes you read. I'm guessing you want to have a String that's only as long as the number of bytes, 'len', you've read, in which case you only want to use 'len' bytes from the byte array 'b.' Like so:
String s = new String(b);
String s = new String(b, 0, len);