public class Print {
public static void handlewords() throws IOException {
String path = "Dictionary.txt";
String path1 = "training.txt";
//read wordlist(dictionary)
File file = new File(path2);
PrintWriter pw = new PrintWriter(file);
// read the articles
Features ft = new Features();
String content = ft.readFile(path);
String [] words = content.split(" ");
StringBuffer bs = new StringBuffer();
FileReader fr = new FileReader(path1);
BufferedReader br = new BufferedReader(fr);
String line = null;
while ((line = br.readLine()) != null) {
bs.append(line+"\n");
}
br.close();
String str = bs.toString();
String [] word = str.split(" ");
List<String> list1 = new ArrayList<String>(words.length);
List<String> list2 = new ArrayList<String>(word.length);
for(String s: words){
list1.add(s);
}
for(String x: word){
list2.add(x);
HashSet set = new HashSet(list2);
list2.clear();
list2.addAll(set);
}
System.out.print("{");
for(String x: list1){
for(String y: list2){
if(x.equalsIgnoreCase(y)){
System.out.print(list1.indexOf(x));
}
}
}
System.out.print("}");
}
}
我的目的是检查文章中的单词是否也在字典中并将其打印出来。我已经完成了一篇文章的处理,但我仍然坚持处理我的training.txt文件中的几篇文章。 我的培训文件如下所示:
1。&#34;我正在编程......&#34; -----这是第一篇文章
2。&#34;我也在编程......&#34; -----这是第二篇文章。
<磷>氮。 &#34; .............&#34; -----这是第n篇文章。 我的代码适用于一篇文章,但如何处理多篇文章? 输出应为: