public static void main(String[] args) {
String path1="F:/1.txt";
String path2="F:/2.txt";
FileWriter fw=null;
FileReader fr=null;
try {
fw=new FileWriter(path2);
fr=new FileReader(path1);
//方式一:按字节写入
/*int temp=0;
while((temp=fr.read())!=-1) {
fw.write(temp);
}
*/
//方式二:按字符数组写入
char[] data=new char[1024];
int temp2=0;
while((temp2=fr.read(data))!=-1) {
fw.write(new String(data,0,temp2));
}
fw.flush();
} catch (Exception e) {
// TODO: handle exception
}
}
网友评论