FileReader、FlieWriter分别对InputStreamReader、OutputStreamWriter封装了一个构造方法

来源:互联网 发布:linux图形工作站 编辑:程序博客网 时间:2024/04/29 19:23

FileReader源代码:

public class FileReader extends InputStreamReader{........public FileReader(String fileName) throws FileNotFoundException {        super(new FileInputStream(fileName));//向父类传了一个字节流对象,这个父类构造方法使用默认码表    }........}
InputStreamReader源代码:

public class InputStreamReader extends Reader {......//使用默认码表的构造方法 public InputStreamReader(InputStream in) {        super(in);        try {            sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object        } catch (UnsupportedEncodingException e) {            // The default encoding should always be available            throw new Error(e);        }    }......}

所以,使用FileReader,与使用public InputStreamReader(InputStream in) 的编码表都是默认的。功能一样

FlieWriter同理。

从源码也可看出,无论字节流还是字符流,操作的都是字节数据。

0 0
原创粉丝点击