import java.io.*;
public class CopyDemo {
/**
* @param args
*/
public static void main(String[] args) {
FileWriter fw=null;
FileReader fr=null;
try{
fw=new FileWriter("demo.text");
fr=new FileReader("demo.java");
char[] buf=new char[1024];
int len=0;
while((len=fr.read(buf))!=-1){
fw.write(buf,0,len);
}
}catch(IOException e){
throw new RuntimeException("复制文件失败!");
}finally{
if(fr!=null){
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
|
|