java - How to Convert InputStream.read(new byte[1024]); to String? -


I would like to get data from InputStream () as a code Hi, start, stop , e.t.c.

My code is piece

  byte [] buffer = new byte [1024]; InputStream.read (buffer);   

My data has been sent from Bluetooth to the above code piece only (like 2 if I sent hi, 5 starts if sent), then send me normal from sender Will have to go back like string.

I only changed the string in InputStream . Any suggestions, I appreciate it!

Finally, I can solve it! InputStream.read (buffer); Only how many bytes are in the buffer, and return the integer number of socket data stored in the buffer. So, with buffer you get the string eg String result = new string (buffer);

Comments