[Java] Android从 HttpResponse (或者InputStream) 获取字符串内容 →→→→→进入此内容的聊天室

来自 , 2020-04-13, 写在 Java, 查看 164 次.
URL http://www.code666.cn/view/aafd8346
  1. // Fast Implementation
  2. private StringBuilder inputStreamToString(InputStream is) {
  3.     String line = "";
  4.     StringBuilder total = new StringBuilder();
  5.    
  6.     // Wrap a BufferedReader around the InputStream
  7.  
  8.     // Read response until the end
  9.     while ((line = rd.readLine()) != null) {
  10.         total.append(line);
  11.     }
  12.    
  13.     // Return full string
  14.     return total;
  15. }
  16.  
  17. // Slow Implementation from sharejs.com
  18. private String inputStreamToString(InputStream is) {
  19.     String s = "";
  20.     String line = "";
  21.    
  22.     // Wrap a BufferedReader around the InputStream
  23.    
  24.     // Read response until the end
  25.     while ((line = rd.readLine()) != null) { s += line; }
  26.    
  27.     // Return full string
  28.     return s;
  29. }
  30.  
  31. //java/8699

回复 "Android从 HttpResponse (或者InputStream) 获取字符串内容"

这儿你可以回复上面这条便签

captcha