我尝试做的是列出我的个人浏览历史记录,并根据非常长的域列表进行检查。当在我的历史记录中找到域时,我希望将域打印到文件中。我试过使用String.indexOf()和String.contains()方法无济于事。我将使用contains方法发布我目前所拥有的内容。我之前只使用垃圾数据和关键字列表而不是域名,但是当我切换到实际参数而不是我用来测试它时,它只是破坏了。
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
public class Comparator {
public static void main (String[] args) throws Exception{
File sites = new File("sites.txt");
File history = new File("history.txt");
BufferedReader sitesS = new BufferedReader(new FileReader (sites));
BufferedReader historyS = new BufferedReader(new FileReader (history));
PrintWriter output = new PrintWriter("output.txt");
ArrayList<String> historyL = new ArrayList();
String read = new String("");
String compare = new String("");
boolean index = true;
boolean match = false;
while ((read = historyS.readLine()) != null) {
read = read.toLowerCase();
historyL.add(read);
}
historyS.close();
System.out.println("After History is closed.");
while ((read = sitesS.readLine()) != null) {
read = read.toLowerCase();
for (int i = 0; i < historyL.size() && match == false; i++) {
compare = historyL.get(i).toString();
compare = compare.toLowerCase();
index = compare.contains(read);
System.out.println(index);
if (index == true) {
System.out.println("Output should be in the file");
output.println(read);
match = true;
}
}
match = false;
}
sitesS.close();
output.close();
}
}
编辑:我正在测试的history.txt文件的小片段:http://pastebin.com/Ju4cPv9p sites.txt测试集我正在使用:http://pastebin.com/aiurExWb