我当前的代码需要从网上读取外来字符,目前我的解决方案有效,但速度非常慢,因为它使用InputStreamReader通过char读取char。无论如何要加快速度并完成工作吗?
// Pull content stream from response
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
StringBuilder contents = new StringBuilder();
int ch;
InputStreamReader isr = new InputStreamReader(inputStream, "gb2312");
// FileInputStream file = new InputStream(is);
while( (ch = isr.read()) != -1)
contents.append((char)ch);
String encode = isr.getEncoding();
return contents.toString();
答案 0 :(得分:6)
有效阅读 字符,数组和行。
InputStreamReader isr = new InputStreamReader(inputStream, "gb2312");
Reader reader = new BufferedReader(isr);