Java IO流之普通文件流和随机读写流区别

来源:互联网 发布:python模块化编程实例 编辑:程序博客网 时间:2024/06/06 07:02

普通文件流和随机读写流区别

普通文件流:http://blog.csdn.net/baidu_37107022/article/details/71056011

FileInputStream和FileOutputStreamFileReader和FileWriter

随机读写流:http://blog.csdn.net/baidu_37107022/article/details/71107086

RandomAccessFile

两者区别:

1.流向分类差别

普通文件流:分输入流和输出流随机读写流:既是输入流也是输出流

2.基本方法区别

普通文件流:拥有所有共性方法,    比如read(),write(),close(),flush(),skip()等等方法

随机读写流:除了拥有这些共性方法,还有自己特有的方法,    比如readLine(),seek(),skipBytes()等等方法    特别注意:随机读写流没有flush()方法

3.构造方法区别

普通文件流:1)输入流:参数都文件路径FileInputStream(File file)     FileInputStream(String name) 2)输出流:参数1--都是文件路径;    FileOutputStream(File file)    FileOutputStream(String name) 参数2 append:true时--写入时不覆盖原有内容,而是在文件内容后面接着写;false--写入时会覆盖原有内容,没有第二个参数时默认是false    FileOutputStream(File file, boolean append)     FileOutputStream(String name, boolean append) 

随机读写流:参数1:都是文件路径;参数2:是读写模式,只有两个取值--r或rwRandomAccessFile(File file, String mode) RandomAccessFile(String name, String mode) 

4.读写位置区别

普通文件流:只能在指定位置【读取】--skip()方法,不能指定位置写入随机文件流:可以在指定位置进行【读写】,使用seek()方法

5.应用区别

普通文件流:使用普通文件流不能进行多线程复制随机读写流:可以进行多线程复制
0 0