title: Java Scanner Read from File
body: <p>Let me first establish the following fact: I am new to java, so please be patient.</p>
  
  <p>In my programming class, we were given an exercise to do at home using the Scanner class. The activity shows the following coding to exercise with: </p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class FileReadWrite {
  
       public static void main(String[] args) throws FileNotFoundException {
            String[] strArr = new String[100];
  
            int size = 0;
  
            try {
                 Scanner scFile = new Scanner(new File("Names1.txt"));
                 while (scFile.hasNext()) {
                      strArr[size] = scFile.next();
                      size++;
                 }
                 scFile.close();
  
                 for (int i = 0; i &lt; size; i++) {
                      System.out.print(strArr[i] + " ");
                 }
            } catch (FileNotFoundException e) {
                 System.err.println("FileNotFoundException: " + e.getMessage());
            }
  
       }
  }
  </code></pre>
  
  <p>The program seems to not be working correct. I use NetBeans to run the code, and when I run the code, it does not display the data in the text file, Names.txt. Why is that? The program does however Build completely without errors.</p>
  
  <p>I have tried going through the Scanner class javadocs, but it's not helping me.</p>
  
  <p>Please explain to me so that I can learn from the mistake made.</p>
  
  <p>Thanks,
  Johan</p>