编码之间的相互转换
package io; import java.io.*; public class DemoInput { /* * 练习: * 文件编码转换 * 将gbk编码转换为utf-8编码 * 分析: * 1、创建inputsteramreader对象,构造方法中传递字节输入流和指定的编码名称 * 2、创建outputsteramreader对象,构造方法中传递字节输出流和指定编码表名称 * 3、使用read读取文件 * 4、使用write写入文件 * 5、释放资源 * */ public static void main(String[] args) throws IOException { InputStreamReader isr = new InputStreamReader(new FileInputStream("F:\\新建文件夹\\usan.fa\\jbd"),"jdb"); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\新建文件夹\\usan.fa\\asd.txt"),"utf-8"); int len=0; while((len = isr.read())!=-1){ osw.write(len); } isr.close(); osw.close(); } }