In that case the contents of your text file actually contains
and not what you posted in reply #7. This could have happened because your code called save() previously and overwrote the data file.
To deal with the NoSuchElementException restore the data file and use the debugging code as posted. It is designed to give quite a few lines of output, not one.
[Edit]
It would be a good idea to separate files for input and output in order to avoid this sort of confusion.
And to add a line of debugging code to the save method:
|
Code:
|
public void save(String pirateTxt) throws IOException{
// etc
outfile.println(phrase.size());
for (Phrases p:phrase) {
System.out.println("About to write the line " + p.toString() + " into the data file");
outfile.println(p.toString());
}
outfile.close();
} |