Ren*_*ani 6 java webpage bufferedreader
我使用 HttpURLConnection.getInputStream() 下载了一个网页并将内容转换为字符串,我执行以下方法:
String content="";
isr = new InputStreamReader(pageContent);
br = new BufferedReader(isr);
try {
do {
line = br.readLine();
content += line;
} while (line != null);
return content;
} catch (Exception e) {
System.out.println("Error: " + e);
return null;
}
Run Code Online (Sandbox Code Playgroud)
页面下载速度很快,但是把内容转成String的处理很慢。还有另一种方法可以更快地将内容转换为字符串吗?
我将其转换为 String 以插入到数据库中。