字符输入流与字符输出流

字符输入流

public class CharSetTest00 {
public static void main(String[] args) throws Exception{
//代码UTF-8 文件GBK "D:\\resources\\data.txt"
//1. 提取GBK文件的原始字节流

InputStream is = new FileInputStream("D:\\resources\\data.txt");
//2. 把原始字节流转换成字符输出流
//Reader isr = new InputStreamReader(is);//默认以UTF-8 转化成字符流, 还是会乱码
Reader isr = new InputStreamReader(is,"GBK");// 以指定的GBK编码转换成字符输入流
}
}

字符输出流
public class OutputStreamWriterDemo02 {
public static void main(String[] args) throws Exception{
//定义一个原始字节输出流
OutputStream os = new FileOutputStream("D:\\resources\\data.txt");

//把原始的字节输出流转换成字符输出流
Writer osw = new OutputStreamWriter(os,"GBK");//指定GBK方式写字符出去
//把低级的字符输出流 包装成高级的缓冲字符输出流
BufferedWriter bw = new BufferedWriter(osw);
}
}

posted on 2022-03-29 17:14  我要当程序源  阅读(115)  评论(0编辑  收藏  举报

导航