BufferedReader

wwwasp 2004-06-23 02:43:31
FileReader fr = new FileReader("d:/temp.txt");
BufferedReader br = new BufferedReader(fr);

String s;
while((s = br.readLine()) != null)
{
System.out.print(s);
}
fr.close();

这里为什么用BufferedReader,只是为了用readLine()吗?
...全文
161 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwasp 2004-06-23
  • 打赏
  • 举报
回复
哦,是这样

CharArrayWriter和CharArrayReader以数组做为输出/入流的目的的实现,在实际应用中有什么用呢?
bon_jovi 2004-06-23
  • 打赏
  • 举报
回复
n general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,

BufferedReader in
= new BufferedReader(new FileReader("foo.in"));

will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

文档写的很清楚。如果不用缓存,每次读都要先读取bytes然后转成字符,再返回。效率低啊。
oswicer 2004-06-23
  • 打赏
  • 举报
回复
看API文档!
wwwasp 2004-06-23
  • 打赏
  • 举报
回复
缓存起来???
为什么要缓存起来呢?
FileReader对象实例保存着不行吗?
blasterboy 2004-06-23
  • 打赏
  • 举报
回复
BufferedReader
可以把输入缓存起来

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧