zoukankan      html  css  js  c++  java
  • 字符流

    字符流:
    字符输入流(读)
    Reader类抽象类
    Reader类的常用方法:
    int read()
    int read(char[] c)
    read(char[] c,int off,int len)
    void close()
    InputStreamReader类可以指定字符编码格式
    Reader类的子类InputStreamReader常用的构造方法
    new InputStreamReader(InputStream in)
    new InputStreamReader(InputStream in,String charSetName)
    传入的是字节输入流对象,所以使用前要创建FileInputStream对象
    charsetName指定的编码格式
    FileReader类不可以指定字符编码格式,按照文件系统默认编码格式去读
    InputStreamReader类的子类FileReader的构造方法
    new FileReader(File file)
    new FileReader(String pathname)
     
    中文乱码
    原因:文件编码格式  和  程序环境的编码格式不一致
     
    解决方案: 字符流去读的时候,指定字符流的编码格式
     
    System.out.println(System.getProperty("file.encoding"))(获得本地平台的字符编码类型)
    txt文本的编码格式是ANSI(GBK)
     
    缓冲流:
    BufferedReader类
    Reader类的子类BufferedReader类使用BufferedReader要传入Reader对象,所以使用前要先创建Reader对象
    readLine()
     
     
    字符输出流(写)
    Writer类抽象类
    Writer类的常用方法
    writer(String str)
    writer(String str,int off,int len)
    void close()
    void flush() 清空缓存
    OutputStreamWriter类可以指定字符编码格式
    Writer类的子类OutputStreamWriter类常用的构造方法
    new OutputStreamWriter(OutputStream out)
    new OutputStreamWriter(OutputStream out,String charSetName)
    charsetName指定的编码格式
    FileWriter类不可以指定字符编码格式,会按照文件系统默认编码格式去写
    InputStreamWriter类的子类FileWriter的构造方法:以下两种构造,都可以重载,指定一个boolean类型的参数,用来指定追加还是覆盖文件内容
    new FileWriter(File file)
    new FileWriter(String pathname)
     
    缓冲流:
    BufferedWeiter类
    Writer类的子类BufferedWriter类常用的构造方法
    new BufferedWriter(Writer out)
     
    newLine() 创建新的一行
     

  • 相关阅读:
    apt-get connects to web
    Particle Filter(CC) 放狗
    Get a specific pixel coordinates where your mouse on (cc)
    event
    两张图片的平移实验 (SLAM translate epipolar geometry)
    vs2010 LINK : fatal error LNK1123: 转换到 COFF 期间失败:(cc)
    fx and fy in Calibration
    How do I get add-apt-repository to work through a proxy?
    ROS and PCL install
    Longest palindrome subsequence
  • 原文地址:https://www.cnblogs.com/KiligYou/p/10978851.html
Copyright © 2011-2022 走看看