Java Dosya Kopyalama

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Copy {

public static void main(String[] args) {
File kaynak = new File("java.txt");
File hedef = new File("eclipse.txt");
BufferedReader br = null;
PrintWriter pw = null;
try {
br = new BufferedReader(new FileReader(kaynak));
pw = new PrintWriter(new FileWriter(hedef));
if (hedef.createNewFile()) {
System.out.println("Başarıyla dosya oluşturuldu");
}

String satir;
while ((satir = br.readLine()) != null) {
pw.println(satir);
System.out.println(satir);
}
} catch (IOException e1) {
e1.printStackTrace();
}

finally {
pw.close();
}
}

}

« »