I have an assignment due for university regarding a spellchecker program that uses a dictionary text file provided to us with one word a line for a couple hundred words. I have thus been experimenting with self made simple reading files(chinese.txt) in code for only the duration required instead of the entire dictionary at the start. I made two classes one with the read file function and one to execute it (spellchecker). however when i try to execute i keep getting the same error regardless of what i change saying exception in thread.
readfile.java:
package coursework2;
import java.io.*;
import java.util.*;
public class readfile {
private Scanner x;
public void openFile() {
try {
x = new Scanner(new File("chinese.txt"));
}
catch(Exception e) {
System.out.println("Not found");
}
}
public void readFile() {
while(x.hasNext()) {
String a = x.next();
String b = x.next();
String c = x.next();
System.out.printf("%s %s %s", a,b,c);
}
}
public void closeFile() {
x.close();
}
spellchecker.java:
epackage coursework2;
class spellchecker {
public static void main(String[] args) {
readfile r = new readfile();
r.openFile();
r.readFile();
r.closeFile();
}
}
text file (chinese) just has a couple words 3 per line hence the formatting of the print method. if anyone can let me know how to get rid of this error or a better method to start on my approach to this spell checker program it would be greatly appreciated. As my actual project requires a use of a dictionary which has a couple thousand variables probably.
Kind Regards
1st year java learner.