我使用的两个文件是 1.Details.txt
Code|Account No.|City
100051001|999001|Delhi
200051003|999002|Kanpur
180051012|999003|Jammu
2.Sal.txt
Code|Amount
100051001|100
200051001|200
180051012|123
输出应该是
100051001 999001 Amount 100 INR Delhi
180051012 999003 Amount 123 INR Jammu
我试过的代码如下:-
//Code to get the output
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
public class compareArrayList {
public static void main(String[] args) throws FileNotFoundException {
String credit_file_name ="C:/transfer/Sal.txt";
String file_branches ="C:/transfer/Details.txt";
BufferedReader reader0;
BufferedReader reader1;
ArrayList<String> branch_list = new ArrayList<String>();
ArrayList<String> credit_file = new ArrayList<String>();
try {
reader0 = new BufferedReader(new FileReader(file_branches));
reader1 = new BufferedReader(new FileReader(credit_file_name));
String data ="";
String acct_num = "";
String city ="";
String amount1 ="";
String line0 = reader0.readLine();
String line1 = reader1.readLine();
while (line0 != null) {
branch_list.add(line0);
line0 = reader0.readLine();
}
Collections.sort(branch_list);
reader0.close();
while (line1 != null) {
}
}
}
我得到的输出如下:-
100051001 999001 Amount 100 INR Delhi
180051012 999003 Amount 123 INR Jammu
180051012 999003 Amount 123 INR Jammu
这有重复的记录。
守着一只汪
相关分类