package com.test.io01;import java.io.*;public class Test04Throws {public static void main(String[] args){//1.有一个源文件File f1 = new File("d:\\Test.txt");//2.有一个目标文件File f2 = new File("d:\\Demo.txt");//3.搞一个输入的管,怼到源文件上FileReader fr = null;FileWriter fw = null; //fw初始化一下try {fr = new FileReader(f1);//4.搞一个输出的管,怼到目标文件上fw = new FileWriter(f2);//5.开始动作//方式:利用缓冲字符数组,将数组转为String写出。char[] ch = new char[5];int len = fr.read(ch);while (len != -1) {String s = new String(ch, 0, len); //将缓冲数组转换为字符串写入fw.write(s);System.out.println(len);len = fr.read(ch);}}catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {//6.关闭流 (关闭流的时候,倒着关闭,后用先关)try {if(fw != null) { //防止空指针异常fw.close();}} catch (IOException e) {e.printStackTrace();}try {if(fr != null) { //防止空指针异常fr.close();}} catch (IOException e) {e.printStackTrace();}}} }