title: Creating a custom iterator that reads consecutive files
body: <p>We have </p>
  
  <pre><code>public class UKWacSentenceIterator implements SentenceIterator
  </code></pre>
  
  <p>which is obviously an Tterator but I don't have any information on what's in <code>SentenceIterator</code>. This class has this property: <code>Scanner fileScanner</code>.</p>
  
  <p>The idea is that the constructor takes an array of files:</p>
  
  <pre><code>public UKWacSentenceIterator() throws IOException {
      Properties p = new Properties();
      p.load(prop.class.getClassLoader()
             .getResourceAsStream("sources/ukwacdump.properties"));
      Enumeration&lt;Object&gt; keys = p.elements();  
      while (keys.hasMoreElements()) { 
          source.add(keys.nextElement());
      }
      fileScanner = new Scanner(new File((String) source.get(0)));
  }
  </code></pre>
  
  <p>And in the main method we can use a for loop:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      for(String line : new UKWacSentenceIterator()) {
          System.out.println(line);   
      }
  }
  </code></pre>
  
  <p>He has currently having a problem with this for loop because once the first file is <code>EOF</code> the for just stops. So he thought would be a good idea to override</p>
  
  <pre><code>@Override
  public boolean hasNext() {
      if(tmp != null) {
          return true;
      }
      if (this.fileScanner.hasNext()) {
          try {
              this.skipToSequenceStart();
              String sent = this.scanSentence();
              this.tmp = sent;
              return true;
          } catch (Exception e) {
              return false;
          }
      } else {
          return advanceFileScanner();
      }
  }
  </code></pre>
  
  <p>But he doesn't know how to build <code>advanceFileScanner()</code>.</p>
  
  <p>My idea is to just to assign the variable <code>fileScanner</code> to a new <code>Scanner</code> with the next file name and then just copy </p>
  
  <pre><code>this.skipToSequenceStart();
  String sent = this.scanSentence();
  this.tmp = sent;
  return true;
  </code></pre>
  
  <p>I don't know if he tried yet. I was wondering if you think is a good idea and if you can suggest me a good tutorial on how to create an iterable object. Because right now I'm just guessing, I don't know what the for loop use other than <code>hasNext()</code>.</p>