gpt4 book ai didi

java:加快读取外文字符

转载 作者:行者123 更新时间:2023-11-29 07:22:12 25 4
gpt4 key购买 nike

我当前的代码需要从 web 读取外来字符,目前我的解决方案有效但速度很慢,因为它使用 InputStreamReader 逐个字符地读取。有没有办法加快速度并完成工作?

// 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();

最佳答案

BufferedReader 包裹你的 InputStreamReader

for the efficient reading of characters, arrays, and lines.

InputStreamReader isr = new InputStreamReader(inputStream, "gb2312");
Reader reader = new BufferedReader(isr);

关于java:加快读取外文字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2610991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com