最初のテキスト ファイル
A.txt
;
asdfghjklqw12345 qwe3456789
asdfghjklqw12345 qwe3456789
2 番目のテキスト ファイル
B.txt
。
|レコード 1: 拒否 - 表 AUTHORIZATION_TBL、列 AUTH_DATE.ORA-01843 のエラー: 有効な月ではありません| |レコード 2: 拒否 - 表 AUTHORIZATION_TBL、列 AUTH_DATE.ORA-01843 のエラー: 有効な月ではありません|
3 番目のテキスト ファイル
C.txt
。
asdfghjklqw12345 qwe3456789 |レコード 1: 拒否 - テーブル AUTHORIZATION_TBL、列 AUTH_DATE.ORA-01843 のエラー: 有効な月ではありません|
asdfghjklqw12345 qwe3456789 |レコード 2: 拒否 - テーブル AUTHORIZATION_TBL、列 AUTH_DATE.ORA-01843 のエラー: 有効な月ではありません|
2つの異なるテキストファイルから2行を1行にマージしたい上記の状況では、私のコードは以下のとおりです
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();
}