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 }