作用
将字节输入流转换为字符输入流(InputStreamReader)
将字符输出流转换成字节输出流(OutPutStreamWriter)
使用方法
- 造文件
- 造流
- 操作文件
- 关闭流
实现uft-8文件转换成gbk文件
实际上应该使用try-catch-finally方法,这里为了看的简洁明了,直接抛出异常
@Test
public void test1() throws IOException {
FileInputStream fis = new FileInputStream("helloworld.txt");
FileOutputStream fos = new FileOutputStream("helloworld_gbk.txt");
InputStreamReader isr = new InputStreamReader(fis,"utf-8");
OutputStreamWriter osw = new OutputStreamWriter(fos,"gbk");
char[] cbuf = new char[10];
int len;
while ((len = isr.read(cbuf)) != -1){
osw.write(cbuf,0,len);
}
osw.close();
isr.close();
}