zoukankan      html  css  js  c++  java
  • Java IO流之普通文件流和随机读写流区别

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

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

    FileInputStream和FileOutputStream
    
    FileReader和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或rw
    RandomAccessFile(File file, String mode) 
    
    RandomAccessFile(String name, String mode) 
    

    4.读写位置区别

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

    5.应用区别

    普通文件流:使用普通文件流不能进行多线程复制
    
    随机读写流:可以进行多线程复制
    
  • 相关阅读:
    201. Bitwise AND of Numbers Range
    200.Number of Islands
    199. Binary Tree Right Side View
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    odoo pivot filed字段设置
    postgres 实现查找所有的子记录,child_of
    postgres 查询返回记录集的函数
    python GUI编程/窗口编程之easygui
  • 原文地址:https://www.cnblogs.com/TCB-Java/p/6809628.html
Copyright © 2011-2022 走看看