简单写了一个
package cn.os;
import java.io.*;
public class MergedDocuments {
public static void main(String[] args) throws IOException {
String ff = "C:\\Users\\Administrator\\Desktop\\DianCai\\src\\cn\\os\\";
File file = new File(ff+"target");
File file1 = new File(ff+"source1");
File file2 = new File(ff+"source2");
String str=MergedDocuments.getText(file1,file2);
System.out.println(str);
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(str);
bw.close();
}
public static String getText(File... file) throws IOException {
StringBuilder result = new StringBuilder();
String str;
for(File f : file){
BufferedReader br = new BufferedReader(new FileReader(f));
while((str = br.readLine()) !=null){
result.append(System.lineSeparator()+str);
}
br.close();
}
return result.toString();
}
}
希望能帮到你