【发布时间】:2012-07-09 11:50:13
【问题描述】:
我有两个文件,它们应该在子字符串 0 和 10 之间包含相同的值,但不是按顺序排列的。我已经设法输出每个文件中的值,但我需要知道如何报告说值在第一个文件中和第二个文件中的值,反之亦然。文件采用这些格式。
6436346346....Other details
9348734873....Other details
9349839829....Other details
第二个文件
8484545487....Other details
9348734873....Other details
9349839829....Other details
第一个文件中的第一条记录没有出现在第二个文件中,第二个文件中的第一条记录也没有出现在第一个文件中。我需要能够以这种格式报告这种不匹配:
Record 6436346346 is in the firstfile and not in the secondfile.
Record 8484545487 is in the secondfile and not in the firstfile.
这是我目前拥有的代码,它为我提供了两个文件所需的输出以进行比较。
package compare.numbers;
import java.io.*;
/**
*
* @author implvcb
*/
public class CompareNumbers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
File f = new File("C:/Analysis/");
String line;
String line1;
try {
String firstfile = "C:/Analysis/RL001.TXT";
FileInputStream fs = new FileInputStream(firstfile);
BufferedReader br = new BufferedReader(new InputStreamReader(fs));
while ((line = br.readLine()) != null) {
String account = line.substring(0, 10);
System.out.println(account);
}
String secondfile = "C:/Analysis/RL003.TXT";
FileInputStream fs1 = new FileInputStream(secondfile);
BufferedReader br1 = new BufferedReader(new InputStreamReader(fs1));
while ((line1 = br1.readLine()) != null) {
String account1 = line1.substring(0, 10);
System.out.println(account1);
}
} catch (Exception e) {
e.fillInStackTrace();
}
}
}
请帮助我如何有效地实现这一目标。 我想我需要说我是 Java 新手,可能不会轻易抓住这些想法,但我正在尝试。
【问题讨论】:
标签: java bufferedreader