第一個文本文件 A.txt
;合併兩個文本文件逐行使用java
asdfghjklqw12345 qwe3456789
asdfghjklqw12345 qwe3456789
第二個文本文件 B.txt
;
|記錄1:被拒絕 - 表AUTHORIZATION_TBL上的錯誤,AUTH_DATE.ORA-01843列:不是有效月份| |記錄2:被拒絕 - 表AUTHORIZATION_TBL上的錯誤,列AUTH_DATE.ORA-01843:不是有效月份|
第三文本文件 C.txt
;
asdfghjklqw12345 qwe3456789 |記錄1:被拒絕 - 表AUTHORIZATION_TBL上的錯誤,列AUTH_DATE.ORA-01843:不是有效月份|
asdfghjklqw12345 qwe3456789 |記錄2:被拒絕 - 表AUTHORIZATION_TBL出錯,AUTH_DATE.ORA-01843列:不是有效月份|
針對上述情況,我想從兩個不同的文本文件的兩行合併成一個line.My代碼如下
List<FileInputStream> inputs = new ArrayList<FileInputStream>();
File file1 = new File("C:/Users/dell/Desktop/Test/input1.txt");
File file2 = new File("C:/Users/dell/Desktop/Test/Test.txt");
FileInputStream fis1;
FileInputStream fis2;
try {
fis1 = new FileInputStream(file1);
fis2= new FileInputStream(file2);
inputs.add(fis1);
inputs.add(fis2);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int total = (int) (file1.length() + file2.length());
System.out.println("total length is " + total);
SequenceInputStream sis = new SequenceInputStream(Collections.enumeration(inputs));
try {
System.out.println("SequenceInputStream.available() = "+ sis.available());
byte[] merge = new byte[total];
int soFar = 0;
do {
soFar += sis.read(merge,total - soFar, soFar);
} while (soFar != total);
DataOutputStream dos = new DataOutputStream(new FileOutputStream("C:/Users/dell/Desktop/Test/C.txt"));
soFar = 0;
dos.write(merge, 0, merge.length);
dos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
什麼你想幹什麼? –
到目前爲止你有嘗試過什麼嗎?如果是,請告訴我們! – clamp
你有什麼試圖實現它? – Kayz