進出口試圖合併兩個文件DOC_A和doc_b到第三個文件,說doc_c與期望的結果是:合併兩個文件面向行
content doc_a: line1
line2
content doc_b: line3
line4
content doc_c: line1 line3
line2 line4
我的做法與此類似:
public static void mergeTrain(File src1, File src2, File dest) throws IOException{
Files.copy(src1.toPath(), dest.toPath());
BufferedReader br = new BufferedReader(new FileReader(src2));
BufferedWriter bw = new BufferedWriter(new FileWriter(dest,true));
String line = new String("Platzhalter");
try {
while(line != null){
line = br.readLine();
if (line !=null){
bw.append(line);
}
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
br.close();
bw.close();
}
由於我選擇的結果是:
content doc_c: line1
line2 line3 line4
我該如何選擇我想要的結果?
注意:我不認爲'NumberFormatException'實際上屬於那裏。我剛從原始代碼中複製出來。 – domsson