Java converts inputstream to string
public static String inputstream2string (InputStream is, String charset) {
Bytearrayoutputstream BAOs = null;
try {
BAOs = new Bytearrayoutputstream ();
int i =-1;
while ((i = Is.read ())!=-1) {
baos.write (i);
}
Return baos.tostring (charset);
} catch (IOException e) {
e.printstacktrace ();
Logger.error ("Filewrutil.inputstream2string (InputStream is, String charset) occur error:"
+ e.getmessage ());
} Finally {
if (null!= baos) {
try {
baos.close ();
} catch (IOException e) {
e.printstacktrace () ;
Logger.error ("Filewrutil.inputstream2string (InputStream is, String charset) occur error:"
+ e.getmessage ());
}
BAOs = null;
}
}
return null;
}
which
Return baos.tostring (CharSet);
This line is very important, if you do not fill in the character code back to the noon, it is easy to appear garbled, can be GBK, UTF-8 and so on, see the actual project code can be;