怎么用java实现将一个文件的内容复制到另一个文件内容的后面
1个回答
展开全部
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileCopy {
static final String fromeFile = "c:\\test1.txt";
static final String toFile = "c:\\test2.txt";
public static void main(String args[]) {
try {
BufferedReader read = new BufferedReader(new FileReader(new File(fromeFile)));
FileWriter write = new FileWriter(new File(toFile), true);
String temp;
while((temp = read.readLine())!=null){
write.write(temp);
}
write.close();
read.close();
System.out.println("内容已从"+fromeFile+"复制追加到"+toFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询