import java.io.*;
import java.util.*;
public class SearchWord {
public static void main(String[] args) throws IOException {
Set<String> words = new HashSet<String>();
for ( int i = 0; i < args.length; i++) {
words.add(args[i]);
}
FileReader FReader = new FileReader(args[0]);
BufferedReader BReader = new BufferedReader(FReader);
String str = "";
while ((str = BReader.readLine())!= null) {
Iterator<String> it = words.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (str.indexOf(s) != -1){
System.out.println(s);
break;
}
}
}
}
}
import java.util.*;
public class SearchWord {
public static void main(String[] args) throws IOException {
Set<String> words = new HashSet<String>();
for ( int i = 0; i < args.length; i++) {
words.add(args[i]);
}
FileReader FReader = new FileReader(args[0]);
BufferedReader BReader = new BufferedReader(FReader);
String str = "";
while ((str = BReader.readLine())!= null) {
Iterator<String> it = words.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (str.indexOf(s) != -1){
System.out.println(s);
break;
}
}
}
}
}
转载于:https://blog.51cto.com/sophi/66376