title: File IO, Reading from file array using a for-each loop ( : ) in java
body: <p>So normally, I know one would use a standard for loop to iterate though the array, like such: </p>
  
  <pre><code>public static void readCodesFromFile(String filename, String[] codes) throws FileNotFoundException {
      try ( Scanner fin = new Scanner(new File(filename) ); ) {
          for (int i = 0; i &lt;= codes.length - 1; i++) {
              codes[i] = fin.nextLine();
          }
      }
  }
  </code></pre>
  
  <p>But, I desperately want to discover how to do this with a for each loop instead. 
  At this point I just need to know if it can be done, but also would love the efficiency and cleanliness of using this loop for this task. I have tried something like this, and moved things around many times, but cannot seem to get anything to read properly. </p>
  
  <p>Below is the for each ( : ) I have been working with:</p>
  
  <pre><code> public static void readCodesFromFile(String filename, String [] codes) throws FileNotFoundException {
       try (Scanner fin = new Scanner(new File(filename) ); ) {
           for (String code : codes) {
              codes = fin.nextLine();
           }
       }
   }
  </code></pre>