FileReader读取的问题

FileReader是用来读取字符文件的便捷类。此类的构造方法夹定默认字符编码和默认字节缓冲区大小都是适当的。要自己指定这些值,可以先在FileInputStream上构造一个InputStreamReader.
FileWriter的问题
FileWriter也是类似
转换流具体案例
将一个Utf-8编码的文件复制成Gbk编码的文件
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class Demo01InputStreamWriter { public static void main(String[] args) throws IOException { InputStreamReader isr = new InputStreamReader(new FileInputStream("G:\\test1\\aa.txt"),"utf-8"); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("G:\\test1\\ttt.txt"),"gbk"); char[] cs = new char[1024]; int len = 0; while((len = isr.read(cs))!=-1){ osw.write(cs,0,len); } osw.close(); isr.close(); } }
|