public String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "/n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
改成:BufferedReader reader = new BufferedReader(new InputStreamReader(is),"UTF-8");
关键看那个流从哪边来的
举个例子
比如你这个流是从磁盘上某个txt文件读取的
1、如果这个文件以ANSI的编码格式保存的,那么
new InputStreamReader(is,"GBK")
2、如果这个文件以UTF-8的形式保存的,那么
new InputStreamReader(is,"UTF-8")
如果是……