怎么从一个java程序里复制文字
发布网友
发布时间:2023-02-16 08:32
我来回答
共1个回答
热心网友
时间:2023-09-16 22:51
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();
}
}
}