- 转换流 InputStreamReader(从文件读内容) , OutStreamWriter(输出/写入内容)
- 当编译器的编码格式和目标文本的编码格式不一致时,使用InputStreamReader , OutStreamWriter进行读写
- 当编译器的编码格式和目标文件的编码格式一致时,使用FileReader , FileWriter进行读写
一、InputStreamReader转换流读文件方法
// 定义转换流读文件方法
private static void Readdata(String readfilepath) throws IOException {
// 创建字节流
FileInputStream fis = new FileInputStream(readfilepath);
// 创建转换流,以指定的编码格式读取内容
InputStreamReader isr = new InputStreamReader(fis,"gbk");
//1、 逐一字节读取
// int cc = isr.read();
// while (cc!=-1){
// System.out.print((char) cc);
// cc= isr.read();
// }
//2、 以数组的形式读取
char[] ch = new char[1024];
int len = isr.read(ch)