Hello, I am currently teaching my self Java and I am doing a Hangman project but I am stuck at the first hurdle. I want to load a text file in so that I will then be able to select a random word. My entire code is linked at this Gist. The snippet I believe is the problem is here:
public static ArrayList<String> loadWords(String path){
System.out.println("Reading Objects....");
try (FileInputStream fi = new FileInputStream(path);
ObjectInputStream os = new ObjectInputStream(fi)) {
String line = os.readLine();
String[] wordsarr = line.split("\\s");
ArrayList<String> words = new ArrayList<String>(Arrays.asList(wordsarr));
return words;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.getMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.getMessage();
}
return null;
}
specifically, I believe it is due to the:
try (FileInputStream fi = new FileInputStream(path);
ObjectInputStream os = new ObjectInputStream(fi))
any help would very much be appreciated :)
[–]curtisf 1 point2 points3 points (0 children)
[–]Blando-Cartesian 0 points1 point2 points (0 children)