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然后转成字符,再返回。效率低啊。
为什么要缓存起来呢?
FileReader对象实例保存着不行吗?
= 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然后转成字符,再返回。效率低啊。