InputStreamReader: 将字节输入流转换字符输入流
OutputStreamWriter:将字节输出流转换字符输出流
读取文件数据
File F = new File("D:\\Demo.txt");//源文件
//字节输入流 读取F文件
FileInputStream fis = new FileInputStream(F);
//转换流 字节输入流 转换 字符输入流 将字节转换字符的时候 按照UTF-8转
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");
// 文件内容 显示控制台
char[] buf = new char[1024];
int read = isr.read(buf);
while (read != -1){
System.out.println(buf);
read = isr.read(buf);
}
isr.close();
写入文件数据
File F = new File("D:\\Demo.txt");//源文件
//字节输出流
FileOutputStream os = new FileOutputStream(F,true);
//字节输出流 转 字符输出流 UTF-8编码方式
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
osw.write("Hello 你好世界");
osw.close();