java InputStream

java InputStream 当为网络数据流是,不能以read为-1作为数据结束的尾。

而用下列案例获取数据。

Log.v(TAG, "==========start=========="); 

         int readBytes=0; 

          

         byte[] b=new byte[1024];//1024可改成任何需要的值 

          

         int len=b.length; 

          

         while (readBytes < len) { 

          

                int read = stream.read(b, readBytes, len - readBytes); 

 

               //判断是不是读到了数据流的末尾 ,防止出现死循环。 

 

                if (read == -1) { 

 

                    break; 

 

                } 

 

                readBytes += read; 

 

            } 

       Log.w(TAG,new String(b, "UTF-8"));
原文地址:https://www.cnblogs.com/swack/p/5709696.html