字符流

字符输入流(读):

Reader类常用方法

int read( )
int read(char[] c)
read(char[] c,int off,int len)
void close( )

FileReader

 new FileReader(File file)

new FileReader(String path)

如果出现中文乱码

原因:文件编码格式 和 程序环境的编码格式不一致

解决方案 :字符流去读的时候,指定字符流的编码格式

FileReader  无法指定编码格式,会按照文件系统默认编码格式读

案例:

 

 

字符输出流(写)

Writer类常用方法

write(String str)
write(String str,int off,int len)
void close()
void flush():清空缓存

FileWriter:一下两种构造方法,都可以重载

                      new FileWriter(File file)

                      new  FileWriter(String path)

案例;

 

 

 

 

posted @ 2020-06-07 15:14  宋凯文  阅读(157)  评论(0)    收藏  举报