- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- //将文件从一个地方拷贝到另一个地方
- public class fileCopy {
- public static void main(String args[]){
- FileReader fr = null;
- FileWriter fw = null;
- char[] temp = new char[1024];
- int num = 0;
- try {
- fr = new FileReader("D:\\test.java");
- fw = new FileWriter("c:\\test.java");
- while ((num = fr.read(temp))!=-1){
- fw.write(temp,0,num);
- num = fr.read(temp);
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- } finally{
- try {
- if(fr!=null)
- fr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try{
- if(fw!=null)
- fw.close();
- } catch(IOException e){
- e.printStackTrace();
- }
- }
- }
- }
复制代码
|
|