3.6
package com.caogao; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; //复制一个字符串 public class Test3 { public static void main(String[] args) { File file = new File("d:/a.txt"); try { file.createNewFile(); System.out.println("文件创建成功"); } catch (IOException e1) { e1.printStackTrace(); } FileInputStream fis = null; FileOutputStream fos = null; InputStreamReader isr = null; BufferedReader bfr = null; try { fis = new FileInputStream("d:/a.txt"); isr = new InputStreamReader(fis,"GBK"); bfr = new BufferedReader(isr); fos = new FileOutputStream("d:/aa.txt"); int len = -1; while((len = bfr.read())!=-1) { System.out.print((char)len); fos.write(len); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }