读整个html文件到字符串? [英] Reading entire html file to String?
本文介绍了读整个html文件到字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String content =;
尝试{
BufferedReader in = new BufferedReader(new FileReader(mypage.html));
String str; ((str = in.readLine())!= null){
content + = str;
}
in.close();
} catch(IOException e){
}
解决方案 div>
这里有 IOUtils.toString(..)
实用程序。
如果您使用 Guava
,还有 Files.readLines(..)
和 文件的ToString(..)
。
Are there better ways to read an entire html file to a single string variable than:
String content = "";
try {
BufferedReader in = new BufferedReader(new FileReader("mypage.html"));
String str;
while ((str = in.readLine()) != null) {
content +=str;
}
in.close();
} catch (IOException e) {
}
解决方案
There's the IOUtils.toString(..)
utility from Apache Commons.
If you're using Guava
there's also Files.readLines(..)
and Files.toString(..)
.
这篇关于读整个html文件到字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文