1public void readFile(String poem){
2 File file = new File(poem);
3
4 try(Scanner input = new Scanner(file)){
5 while(input.hasNextLine()){
6 String line = input.nextLine().toLowerCase();
7 //this splits at punctuation and saves it as a word
8 String[] lineToWord = line.split("\\b");
9 for(String word : lineToWord) {
10 if(!word.equals(" ")){
11 // this ignores spaces when adding to array
12 words.add(word);
13 }
14 }
15 }
16 }
17 catch (java.io.IOException ex) {
18 System.out.println("An error occurred while trying to read poem. Sadge: " + ex);
19 }
20 }