用java实现两个文本文件的复制
推荐于2016-02-27 · 知道合伙人数码行家
关注
展开全部
import java.io.*;
public class ReadWriteFile{
public static void main(String [] args){
try{
File read = new File("c:\\test1.txt");
File write = new File("c:\\test2.txt");
BufferedReader br = new BufferedReader(new FileReadder(read));
BufferedWriter bw = new BufferedWriter(new FileWriter(write));
String temp =null;
temp=br.readLine();
while(temp!=null){
//写文件,只适用与windows系统
bw.write(temp+"\r\n");
//继续写文件
temp = br.readLine();
}
bw.close();
br.close();
}catch(FileNotFoundException fe){
System.out.println(fe.getMessage());
fe.printStackTrace();
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
public class ReadWriteFile{
public static void main(String [] args){
try{
File read = new File("c:\\test1.txt");
File write = new File("c:\\test2.txt");
BufferedReader br = new BufferedReader(new FileReadder(read));
BufferedWriter bw = new BufferedWriter(new FileWriter(write));
String temp =null;
temp=br.readLine();
while(temp!=null){
//写文件,只适用与windows系统
bw.write(temp+"\r\n");
//继续写文件
temp = br.readLine();
}
bw.close();
br.close();
}catch(FileNotFoundException fe){
System.out.println(fe.getMessage());
fe.printStackTrace();
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询