关于java的IO流对InputStream一定要用BufferedInputStream
对OuputStream一定要用BufferedOutputStream
对Reader一定要用BufferedReader
对Writer一定要用BufferedWriter是不是后者的效率要比前者好??BufferedInputStream bis = new BufferedInputStream(new InputStream());
解决方案 »
- |,&,^,<<,>>等等的作用?
- javax.servlet.ServletException: oracle.jdbc.driver.ScrollableResultSet.getBlob(Ljava/lang/String;)Ljava/sql/Blob;这是什么错误?
- AOP是怎么回事?
- 这个 jar 问题, 你知道吗? 教教我
- 能否实现在点击窗口水平排列菜单的时候,有一个窗体不参加排列那?
- [q]这道题选什么, 为什么? 困惑了好久
- 关于在windows2000下安装 jet 1.03的问题。
- 有谁帮我解答一下?
- 请问高手如何去掉JList的边框?
- 循环输入字符到StringBuffer 最后输出字符问题
- 我想做一个曲线走势图,就是读取数据库,然后画一个走势图出来,请问界面和曲线如何画?
- java创建桌面快捷方式
对于以byte形式读写的流,都用stream命名
对于以word形式读写的流,都用buffer命名其实java在io问题上使用了“Decorator”的设计模式,就是用一个类作为另一个类的输入参数。例如:buffer类可以接受网络,文件等形式传入的信息。如果使用“Decorator”的设计模式,则可以使用组合的形式实现buffer+file,buffer+web,buffer+web+file,buffer+file+web的4种情况的读写,而并不需要写7个类实现,现在只需要3个类即可,当数量越大,越能体现此模式的好处。
BufferedXXX确实是增加了对stream的缓冲能力。
不是一定要用到BufferedXXX,但是使用BufferedXXX对stream进行包装,将会使你的程序运行效率大大增加,尤其是在Web app的应用中(在这些应用中,信息的传输是极耗时间的)。
至于congliu朋友的叙述似乎有些问题,如果论命名byte形式的流均为byte stream,字节流;char形式的流均为char stream,字符流。另外,使用装饰模式就是包装了基本的字节流使之拥有诸如文件操作、字符流、缓冲等强大的功能,并不与缓冲说明相冲突。缓冲是说经过BufferedXXX包装了的流将具有缓冲功能,所以一个是功能说明,一个则是实现机制罢了。
@.@||~
这样有助于我们对这个流的使用。封装后的效果!
A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the and reset methods. When the BufferedInputStream is created, an internal buffer array is created. As bytes from the stream are read or skipped, the internal buffer is refilled as necessary from the contained input stream, many bytes at a time. The operation remembers a point in the input stream and the reset operation causes all the bytes read since the most recent operation to be reread before new bytes are taken from the contained input stream.就是在里面添加了一个数组buffer[],用来缓存要读写的数据。
String str = br.readLine();
我到认为congliu回答的应该是实现的方式,而不是实现的作用。他的作用应该是缓冲,并使用装饰模式实现之。@.@||~