1 String result = readFromInputStream(inputStream);//调用处
 2 //将输入流InputStream变为String
 3     public String readFromInputStream(InputStream in) throws IOException {
 4         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 5         byte[] buffer = new byte[1024];
 6         int len = -1;
 7         while ((len = in.read(buffer)) != -1) {
 8             baos.write(buffer, 0, len);
 9         }
10         baos.close();
11         in.close();
12         
13         byte[] lens = baos.toByteArray();
14         String result = new String(lens,"UTF-8");//内容乱码处理
15         
16         return result;
17     
18     }

 

相关文章:

  • 2021-08-26
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-12-12
  • 2021-11-20
猜你喜欢
  • 2022-02-06
  • 2021-09-22
  • 2022-12-23
  • 2022-02-08
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案