package Io.lianxi;
import java.io.*;
public class CopyAtoB {
/**
* 从一个盘中复制一个文件到另一个盘中
*/
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
copy();
}
public static void copy() {
FileWriter fw=null;
FileReader fr=null;
try {
fw=new FileWriter("D:\\javawork\\作业o2\\Demo02.txt");
fr=new FileReader("D:\\javawork\\作业01\\Demo01.txt");
int len=0;
char[] buf= new char[1024];
while ((len=fr.read(buf))!=-1) {
fw.write(buf,0,len);
}
} catch (IOException e) {
// TODO: handle exception
throw new RuntimeException("读取失败");
}
finally{
try {
if (fr!=null) {
fr.close();
}
} catch (IOException e) {
// TODO: handle exception
}
try {
if (fw!=null) {
fw.close();
}
} catch (IOException e) {
// TODO: handle exception
}
}
}
}
|
|