im trying to load a precreated dictionary and i can\'t seem to load it correctly
ID: 3777033 • Letter: I
Question
im trying to load a precreated dictionary and i can't seem to load it correctly, can anyone help?
public class SpellChecker {
private DictionaryInterface myDictionary;
private DictionaryInterface misspelledWords;
public SpellChecker() //TODO
{
this.myDictionary=new HashedDictionary<>();
this.misspelledWords=new HashedDictionary<>();
}
/** * load the words into the dictionary * * loadDictionary method: sampleDictionary.txt contains a list of words, * one word per line. myDictionary instance variable is populated with the * content of the file. For simplicity the key and the value are the same. * * @param theFileName the name of the file holding the words to put in * the dictionary. */
public void loadDictionary(String theFileName) throws IOException //TODO
{
do{ Scanner keyboard = new Scanner(System.in);
String dictionaryword= keyboard.nextLine();
myDictionary.add(dictionaryword,dictionaryword);
System.out.println("dictionaryword = " + dictionaryword);
} while (myDictionary.getSize()<=theFileName.length()); [[[[[[and like this...
}
Explanation / Answer
public void loadDictionary(String theFileName) throws IOException
{
FileInputStream fis = null;
BufferedReader reader = null;
try
{
fis = new FileInputStream(theFileName);
reader = new BufferedReader(new InputStreamReader(fis));
String line = reader.readLine();
while(line != null)
{
line = reader.readLine();
myDictionary.add(line,line);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.