<p>//不带编码的,遇到中文乱码就挂</p>
<p> public static String inputStream2String(InputStream is) throws Exception{ <br>
ByteArrayOutputStream baos = new ByteArrayOutputStream(); <br>
int i=-1; <br>
while((i=is.read())!=-1){ <br>
baos.write(i); <br>
} <br>
return baos.toString(); <br>
}<br>
//带编码的<br>
public static String inputStream2String (InputStream in , String encoding) throws Exception { <br>
StringBuffer out = new StringBuffer(); <br>
InputStreamReader inread = new InputStreamReader(in,encoding); <br><br>
char[] b = new char[4096]; <br>
for (int n; (n = inread.read(b)) != -1;) { <br>
out.append(new String(b, 0, n)); <br>
} <br><br>
return out.toString(); <br>
} </p>
<p></p>
<p> public static String inputStream2String(InputStream is) throws Exception{ <br>
ByteArrayOutputStream baos = new ByteArrayOutputStream(); <br>
int i=-1; <br>
while((i=is.read())!=-1){ <br>
baos.write(i); <br>
} <br>
return baos.toString(); <br>
}<br>
//带编码的<br>
public static String inputStream2String (InputStream in , String encoding) throws Exception { <br>
StringBuffer out = new StringBuffer(); <br>
InputStreamReader inread = new InputStreamReader(in,encoding); <br><br>
char[] b = new char[4096]; <br>
for (int n; (n = inread.read(b)) != -1;) { <br>
out.append(new String(b, 0, n)); <br>
} <br><br>
return out.toString(); <br>
} </p>
<p></p>