本帖最后由 糖伯貓 于 2014-2-9 20:45 编辑
- ServerSocket ss = new ServerSocket(5000);
- Socket s = ss.accept();
- InputStream in = s.getInputStream();
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = in.read(buf))!=-1){
- System.out.println(len);
-
- System.out.println(new String(buf,0,len));
复制代码
这里while循环里面的in.read(buf)返回的是int型值,我打印了下是字符串的长度,这我也点不理解了,再比较这个长度值是否等于-1这个结束标记?
|