RandomAccessFile、FileInputStream和FileOutputStream的区别
1、RandomAccessFile
(1)是基于指针形式读写文件数据的,比较灵活。
(2)有两种创建模式:只读模式和读写模式 。
(3)RandomAccessFile不属于InputStream和OutputStream类。
(4)RandomAccessFile使用随机访问的方式,根据文件的hashcode生成一个位置存入文件,取得时候再反过来根据这个固定的位置直接就能找到文件,File就不能。
(5)RandomAccessFile可以提高读取的速度。
2、FileInputStream和FileOutputStream
(1)FileInputStream及FileOutputStream使用的是流式访问的方式。
(2)InputStream类是所有表示输入流的类的父类,System.in就是它的一个对象。OutputStream是所有表示输出流的类的父类,System.out就间接继承了OutputStream类。
1、RandomAccessFile
(1)是基于指针形式读写文件数据的,比较灵活。
(2)有两种创建模式:只读模式和读写模式 。
(3)RandomAccessFile不属于InputStream和OutputStream类。
(4)RandomAccessFile使用随机访问的方式,根据文件的hashcode生成一个位置存入文件,取得时候再反过来根据这个固定的位置直接就能找到文件,File就不能。
(5)RandomAccessFile可以提高读取的速度。
2、FileInputStream和FileOutputStream
(1)FileInputStream及FileOutputStream使用的是流式访问的方式。
(2)InputStream类是所有表示输入流的类的父类,System.in就是它的一个对象。OutputStream是所有表示输出流的类的父类,System.out就间接继承了OutputStream类。
(3)FileInputStream是InputStream的子类,FileOutputStream是OutputStream的子类
转自:http://blog.sina.com.cn/s/blog_c312ce090102x9al.html