我想知道循环两个 csv 文件并比较它们的列的最合适的方法是什么。具体来说,我想将 csv file1 第 1 列与 csv file2 第 20 列的每次迭代进行比较,并检查是否有匹配项。这是我到目前为止所拥有的。此外 csv file1 比 csv file2 小得多。
public class ClassifyData {
public static void main(String[]args) throws IOException{
File file1 = new File("file1.csv");
File file2 = new File("file2.csv");
FileWriter writer = new FileWriter("/Users/home/Work.csv");
PrintWriter pw = new PrintWriter(writer);
Scanner in = new Scanner(file1);
Scanner in2 = new Scanner(file2);
boolean firstLine = true;
String[] temp = null;
String [] temp2 = null;
String line = null;
String line2 = null;
while((line = in.nextLine())!=null){
temp= line.split(",");
while(line2 = in2.nextLine() !=null){
temp2 = line2.split(",");
if(temp[0] == temp[20]){
System.out.println("match");
pw.append("0");
continue;
}
pw.append("\n");
}
}
pw.flush();
pw.close();
writer.close();
}
}