我有两个文件:
1- 有1400000行或记录 --- 14 MB
2- 有16000000 -- 170 MB的行或记录
我想查找文件1中的每个记录或行是否也在文件2中
我开发了一个Java应用程序,它执行以下操作:逐行读取文件,并将每行传递给遍历文件2的方法
这是我的代码:
public boolean hasIDin(String bioid) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("C://AllIDs.txt"));
long bid = Long.parseLong(bioid);
String thisLine;
while((thisLine = br.readLine( )) != null)
{
if (Long.parseLong(thisLine) == bid)
return true;
}
return false;
}
public void getMBD() throws Exception{
BufferedReader br = new BufferedReader(new FileReader("C://DIDs.txt"));
OutputStream os = new FileOutputStream("C://MBD.txt");
PrintWriter pr = new PrintWriter(os);
String thisLine;
int count=1;
while ((thisLine = br.readLine( )) != null){
String bioid = thisLine;
System.out.println(count);
if(! hasIDin(bioid))
pr.println(bioid);
count++;
}
pr.close();
}
当我运行它时,似乎需要超过1944.44444444444小时才能完成,因为每行处理需要5秒钟。大约需要三个月的时间!
是否有任何想法可以在更少的时间内完成。
提前致谢。