JAVA——缓冲流(字符流 InputStreamReader)

package com.cskaoyan.io02.tranfer.reader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;


* 接着,我们使用Reader,将刚刚写入文本的中文数据,读取到内存中并显示。
但是考虑到,Reader是抽象类,我们只能使用其子类InputStreamReader。

InputStreamReader的构造方法:
// 创建基于默认字符集进行解码的,转化字符输入流对象
public InputStreamReader(InputStream in)

// 创建基于指定字符集进行解码的,转化字符输入流对象
public InputStreamReader(InputStream in,String charsetName)

*/
public class Demo1 {

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
// public InputStreamReader(InputStream in)
FileInputStream fis1 = new FileInputStream("a.txt");
Reader reader1 = new InputStreamReader(fis1);


// public InputStreamReader(InputStream in,String charsetName)
FileInputStream fis2 = new FileInputStream("a.txt");
Reader reader2 = new InputStreamReader(fis2, "UTF-8");


}

}
posted @ 2020-09-02 17:44  LY心情笔记  阅读(245)  评论(0)    收藏  举报