title: Word Count from a file
body: <p>I'm at the start of writing my program (this is for a class) and I'm running into trouble to just write it down. Here's a list of goals I am hoping to meet.</p>
  
  <ol>
  <li>It is a method given a .txt file (using java.io.File)</li>
  <li>It needs to read the file and split the words, duplicates are allowed. (I plan to use String.split and util.regex.Pattern to work out whitespace and punctuation)</li>
  <li>I'm aiming to put the words in a 1D array and then just find the length of the array.</li>
  </ol>
  
  <p>The problem I'm running into is parsing the txt file. I was told in class that Scanner can, but I'm not finding it while R(ing)TFM. I guess I'm asking for some directions in the API that helps me understand how to read a file with Scanner. Once I can get it to put each word in the array I should be in the clear.</p>
  
  <p>EDIT: I figured out what I needed to do thanks to everyone's help and input. My final snippet ends up looking like this, should anyone in the future come across this question.</p>
  
  <pre><code>Scanner in = new Scanner(file).useDelimiter(" ");
  ArrayList&lt;String&gt; prepwords=new ArrayList&lt;String&gt;();
  while(in.hasNext())
  prepwords.add(in.next());
  return prepwords; //returns an ArrayList without spaces but still has punctuation
  </code></pre>
  
  <p>I had to throw IOExceptions since java hates not being sure a file exists, so if you run into "FileNotFoundException", you need to import and throw IOException. At the very least this worked for me. Thank you everyone for your input!</p>