I look for a faster algorithm. I try to verify that a word exist in a dictionary.
Here is my code in java.
public class Searcher {
public static void main(String[] args){
File file = new File("pathToFile");
Scanner scanner = null;
try{
scanner = new Scanner(file);
}catch(FileNotFoundException e){
System.err.println("Le fichier n'a pas ete trouve");
}
//Word to look for.
String word = "mot";
//indicator of word existence.
boolean nonExistence = true;
while(scanner.hasNext()){
if(Pattern.matches(word, scanner.next())){
System.out.println("\"" + word + "\"" + " est un mot francais.");
nonExistence = false;
break;
}
}
if(nonExistence){
System.out.println("\'" + word + "\'" + " n'est pas un mot francais.");
}
}
}
I would like to do not have to explore the whole file. Thanks.