如何在文件(Java)中搜索存储在List<string>中的句子

How to search the sentence stored in a List<string> in a file (Java)

我有两个文件 itemsets.txt 和 combination.txt

itemsets.txt包含客户购买的商品的详细信息。

Butter Bread Jam 
Bread Jam Cheese Tea 
Bread Eggs Coffee 
Tea Coffee Biscuits 
Biscuits Tea 
Nutella Cheese Eggs 
Maggie Coffee 
Eggs Jam Tea 
Maggie Tea 
Biscuits Coffee 
Bread Biscuits Cheese 
Biscuits Nutella 
Coffee Eggs 
Jam Biscuits 
Eggs Bread Biscuits

combination.txt 包含支持度高于平均支持度的项目的所有可能组合。

 Bread 
 Jam 
 Bread Jam 
 Cheese 
 Bread Cheese 
 Jam Cheese 
 Bread Jam Cheese 
 Tea 
 Bread Tea 
 Jam Tea 
 Bread Jam Tea 
 Cheese Tea 
 Bread Cheese Tea 
 Jam Cheese Tea 
 Bread Jam Cheese Tea 
 Coffee 
 Bread Coffee 
 Jam Coffee 
 Bread Jam Coffee 
 Cheese Coffee 
 Bread Cheese Coffee 
 Jam Cheese Coffee 
 Bread Jam Cheese Coffee 
 Tea Coffee 
 Bread Tea Coffee 
 Jam Tea Coffee 
 Bread Jam Tea Coffee 
 Cheese Tea Coffee 
 Bread Cheese Tea Coffee 
 Jam Cheese Tea Coffee 
 Bread Jam Cheese Tea Coffee 

我想在 itemsets.txt 文件中搜索组合。如果 combination.txt 中的字符串存在于文件 itemsets.txt 中,那么该字符串将被复制到一个新的 .txt 文件中。

我该如何进行?

读取itemsets.txt的文件内容,存入数组。现在阅读 combinaton.txt 中的每一行并在 itemsets.txt 中查找匹配项。如果匹配,您可以将其存储在新文件中。 Google 对于标准文件读写代码,它应该很容易获得。 例子: 输入:

FileReader fr=new FileReader(FILENAME);
BufferedReader br =new BufferedReader(fr);

现在 br.readLine() 应该给你输入。 输出:

String str = "Hello";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(str);

希望对您有所帮助。