Okay so I'm making a basic spellchecker. I'm using a relatively small dictionary with about 1000 of the most common english words, all on separate lines in a text file. I'm on windows so I can't use the Linux dictionary.
Anyways, It's not working. And I'm not quite sure why. It may just be because I can't quite tell which classes to use as far as which reader and which tokenizer. Here's my code, hope you can help.
Please note that I'm required to use the Set class for my dictionary. So please do not post a solution wondering why I'm using Set.
Thanks!
EDIT: after testing a few things I've realized that either the dictionary Set probably not being created correctly. I'm not sure why? anyone got an explaination?
import java.io.*;
import java.awt.*;
import java.util.*;
public class spellcheck
{
public static String spellC(String checkedFile)
{
Set dict = new HashSet();
String returnVal = "";
//creating a dictionary set
try{
Reader fileReader = new BufferedReader(new FileReader("C:/Users/KB/Documents/NetBeansProjects/Barta_Kyle_Ass2/test/dictionary.txt"));
StringTokenizer st = new StringTokenizer(fileReader.toString());
while(st.hasMoreTokens())
{
dict.add(st.nextToken());
}
}
catch(IOException e){
returnVal = "IOException at dictionary making process";
}
try{
Reader checkedRead = new BufferedReader(new FileReader(checkedFile));
StringTokenizer checkedToken = new StringTokenizer(checkedRead.toString());
while(checkedToken.hasMoreTokens())
{
if(dict.contains(checkedToken.nextToken()))
{
returnVal = "";
}
else
{
returnVal = checkedToken.nextToken();
}
}
}
catch(IOException i){
returnVal += "\n IOException at Checking File";
}
return returnVal;
}
}