实际开发遇到(InputStream 编码格式转换方法)
/**
* 将InputStream 进行格式转换
* @param is
* @param code
* @return
*/
public static List<String> getStrFromInsByCode(InputStream is, String code){
StringBuilder builder=new StringBuilder();
BufferedReader reader=null;
List<String> list = new ArrayList<>();
try {
reader = new BufferedReader(new InputStreamReader(is,code));
String line = null;
while((line=reader.readLine())!=null){
builder.append(line+"\n");
list.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
代码如下(示例):
InputStream is = entity.getContent();
List<String> campaignReportList = getStrFromInsByCode(is, "GBK");