zoukankan      html  css  js  c++  java
  • JAVA-流

    1、特点

      1.输入流  定义:数据从数据源(磁盘文件、网络)流向程序(内存)

        表示:I   in

      2.输出流  定义:数据从程序(内存)流向目的地(磁盘文件、网络)

        表示:O  out

    2、字节流  

      1.输出流:FileOutputStream

        构造: new FileOutputStream(“文件全路径”)      覆盖方法

            new FileOutputStream(File对象)        覆盖方法

            new FileOutputStream(“文件全路径”,true)   追加方法

            new FileOutputStream(File,true)       追加方法

        用法:   write(byte[])  写入字节数组

            close()    关闭流,释放资源

      2.输入流:FileInputStream

        构造: new FileInputStream(“文件全路径”)

            new FileInputStream(File对象)

        用法: read(byte[])    读数据到byte[],返回读到数据的长度  

                       分段按顺序读取    

                       读完或读取失败返回-1  

                       while((i=in.read(b))>0){组装数组}

            close()  关闭流

    3、字符流

      1.FileWriter  写

        覆盖方式写入   new FileWriter(“文件全路径”) 

                 new FileWriter(File对象)

        追加方式写入   new FileWriter(“文件全路径”,true)

                 new FileWriter(File对象,true)

        用法  write(String)  写入字符串

            close()  关闭流  

      2.FileReader  读

        构造  new FileReader(“文件全路径”)

            new FileReader(File对象)

        用法  read(char[])  读取字符数据,具体方法和字节流类似

            close()  关闭流

    3、带缓存的字符流

      1.BufferedWriter

        构造:  new BufferedWriter(Write实现类对象)

        用法:  Write(String)  写入字符串

             close()     关闭流

      2.BufferedReader

        构造:  new BufferedReader(Reader实现类的对象)

        用法:  ReadLine  按行读取,返回String

  • 相关阅读:
    Java Web项目开发中常见路径获取方法
    Genymotion模拟器连接不上开发服务器解决办法
    百度鹰眼轨迹管理台部署到本地或者服务器上
    解决Hibernate4执行update操作,不更新数据的问题
    后台发送http请求通用方法,包括get和post
    Java后端发出post请求带参数并接收返回的json
    $.ajax()方法详解
    常见异常及解决办法
    jQuery通过地址获取经纬度demo
    python 导入模块与使用
  • 原文地址:https://www.cnblogs.com/jingfengling/p/5908650.html
Copyright © 2011-2022 走看看