package cn.javastudy.p10.io.demo;
import java.io.*;
/*
* 读取源文件
* 把读取的源文件写到目标文件
*/
public class CopyExpression {
public static void main(String[] args) {
copyData("d:\\demo.txt","E:\\demo.txt");
}
public static void copyData(String res, String des) {
FileReader fr=null;
BufferedReader bfr=null;
FileWriter fw=null;
BufferedWriter bfw=null;
try {
fr=new FileReader("D:\\demo.txt");
fw=new FileWriter("E:\\demo.txt");
bfr=new BufferedReader(fr);
bfw=new BufferedWriter(fw);
String line=null;
while((line=bfr.readLine())!=null)
{
bfw.write(line);
bfw.newLine();
bfw.flush();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}finally{
if(fr!=null)
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
if(fw!=null)
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
}
}
}