字符输入转换流:
//1、提取GBK文件的原始字节流
InputStream is = new FileInputStream("src/file.txt");
//2、把原始字节流转换成字符输入流
// InputStreamReader 默认以UTF-8 的方式转换成字符流
Reader isr = new InputStreamReader(is, "GBK");
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
字符输出转换流:
// 定义一个字节输出流
OutputStream os = new FileOutputStream("src/newFile.txt");
// 把原始的字节输出流转换成字符输出流
Writer osw = new OutputStreamWriter(os,"GBK");
// 把低级的字符输出流包装成高级的缓冲字符输出流
BufferedWriter bw = new BufferedWriter(osw);
bw.write("我爱你中国");
bw.close();