我有两个JSON文件,对象顺序相同。我想同时打印两者中的差异,并打印发生差异的行号。 例如。 输出应为:
”在Expected.json中发现的差异: 在“在此处打印LineNumber”上->在此处打印差异。
类似这样的东西:
Scanner file1 = new Scanner(new File(file1Path));
Scanner file2 = new Scanner(new File(file2Path));
int lineCounter = 1;
while(file1.hasNextLine() && file2.hasNextLine()) {
lineFile1 = file1.nextLine();
lineFile2 = file2.nextLine();
if(!lineFile1.equals(lineFile2)) {
System.out.println("Difference found in Expected.json: on " + lineCounter);
System.out.println("File1 line: " + lineFile1);
System.out.println("File2 line: " + lineFile2);
}
lineCounter++;
}