- public class Copyctod {
-
- public static final String file1 = "c:\\a.txt";
- public static final String file2 = "d:\\d.txt";
- public void copy(String file1,String file2) {
- FileReader fr = null;
- FileWriter fw = null;
- try {
- fr = new FileReader(file1);
- fw = new FileWriter(file2, true);
- char[] buf = new char[1024];
- int num = 0;
- while ((num = fr.read(buf)) != -1) {
- fw.write(buf);
- }
- } catch (Exception e) {
- throw new RuntimeException("读写失败");
- } finally {
- try {
- if (fr != null)
- fr.close();
- if(fw != null) {
- fr.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] args) throws Exception {
- Copyctod c = new Copyctod();
- c.copy(file1, file2);
- }
- }
复制代码 |