InputStreamReader 将字节输入流转换为字符输入流
OutputStreamWriter 将字符输出流转换为字节输出流
@Test public void test2() { //转换流 InputStreamReader isr = null; OutputStreamWriter osw = null; try { //节点流 FileInputStream fis = new FileInputStream("水浒传.txt"); FileOutputStream fos = new FileOutputStream("水浒传_gbk.txt"); //转换流 isr = new InputStreamReader(fis, "utf-8"); osw = new OutputStreamWriter(fos, "gbk"); //复制文件 char[] cbuf = new char[20]; int len; while ((len = isr.read(cbuf)) != -1) { osw.write(cbuf, 0, len); } System.out.println("复制成功"); } catch (Exception e) { e.printStackTrace(); } finally { if(osw != null) { try { osw.close(); } catch (IOException e) { e.printStackTrace(); } } if(isr != null) { try { isr.close(); } catch (IOException e) { e.printStackTrace(); } } } }