public void read(String file_name){
WordNode node = new WordNode();
PhraseNode Node = new PhraseNode();
String [] components = new String[6];
String line = null;
int i = 0;
try{
// file stream classes
FileReader file_in = new FileReader(file_name);
BufferedReader buffer = new BufferedReader(file_in);
// read from file while the function doesn't return null
while((line = buffer.readLine()) != null){
// if the line isn't the new line character
// then add it to the array of strings
components[i] = line;
++i;
// if i is 6 the array is full
if(i == 6){
// if the last element of the array is "_" then it is a phrase type
// otherwise it is just a word
if(components[4].equals("_")){
Node.set_entry(components[0],components[1]);
Node.set_components(components[2]);
insert(Node);
}
else{
node.set_entry(components[0], components[1]);
node.set_components(components[2],components[3],components[4]);
insert(node);
}
// reset it to fill the array again
i = 0;
}
}
// close the buffer
buffer.close();
}
// required exception handling with file input
catch(FileNotFoundException error){
System.out.println("Unable to open file: " + file_name);
}
catch(IOException error2){
System.out.println("Error reading file");
}
}
this function is reading in lines from a file to fill a binary tree. The while loop doesn't do much except use counter variables to make sure the correct node type is added to the tree.
the file name is an argument. in main it's spelt correctly and the file is in the workspace folder. So I have no idea why FileNotFoundException is thrown.
I don't know much of Java io because we only covered java for a few weeks at the end of my cs class. Any feed back as to why this code might be throwing an exception would be greatly appreciated.