使用编程复制文件

来源:互联网 发布:w7怎么连接网络 编辑:程序博客网 时间:2024/06/05 17:34
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


/**
 * @author Administrator
 * @category 文件复制
 */
public class FileCopyDemo {


public static void main(String[] args) {
FileReader fr = null;
FileWriter fw = null;
System.out.println("start...");
try {
File file = new File("C:/new/new/ll.txt");// 源文件
File dest = new File("C:/new/new/dest.txt");// 目標文件
fr = new FileReader(file);// 创建FileRead对象,准备读文件
fw = new FileWriter(dest);// 创建FileWrite对象,准备写文件
int i;
while ((i = fr.read()) != -1) {
fw.write(i);
}
System.out.println("end...");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fw.flush();
fw.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
0 0