java - Why InputStream.read() returns -1? -
my android smartphone tcpclient , chipkit wf32 wifi module tcp server.
int bytesread; inputstream inputstream = socket.getinputstream(); while ((bytesread = inputstream.read(buffer)) != -1){ bytearrayoutputstream.write(buffer, 0, bytesread); response += bytearrayoutputstream.tostring("utf-8"); }
the above code reads data stream , copies buffer. if no data coming block. getting -1. can explains reason getting -1? in document mentioned "end of stream reached". can explain meaning of that? thank you.
if can read documentation see -1
signifies end of stream:
inputstream.read()
so it's natural -1
.
Comments
Post a Comment