Java Reader,Writer类实现字符流文件拷贝
package IO;
import java.io.*;
public class Char_rw {
public static void main(String[] args) {
File src=new File("src/IO/src_path/abc.txt");
File dest=new File("src/IO/dest_path/dest.txt");
Reader reader=null;
Writer writer=null;
try {
reader=new FileReader(src);
writer=new FileWriter(dest,true);
char[] temp=new char[1024];
int len=-1;
while((len=reader.read(temp))!=-1){
writer.write(temp,0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}