package copy2;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class Test {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new FileReader("src/copy2/2.txt"));
BufferedWriter bw=new BufferedWriter(new FileWriter("src/copy2/1.txt"));
String line=br.readLine();
while(line!=null) {
bw.write(line);
bw.newLine();
bw.flush();
line=br.readLine();
}
bw.close();
br.close();
}
}
朴实无华的枯燥分割线
package cn.io;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 字符文件拷贝
* @author Chill Lyn
*
*/
public class Copy2 {
public static void main(String[] args) {
copy("abc.txt", "dest.txt");
}
public static void copy(String srcPath, String destPath) {
File src = new File(srcPath);
File dest = new File(destPath);
try (BufferedReader bs = new BufferedReader(new FileReader(src));
BufferedWriter bw = new BufferedWriter(new FileWriter(dest));) {
String line = null;
while ((line = bs.readLine()) != null) {
bw.write(line);
bw.newLine();
}
bw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
CommonsIO实现方法