title: How to find first string in a text file with a certain length?
body: <p>I'm currently trying to write a program that loops through a text file, to find the first word that is longer than 9 characters. </p>
  
  <p>I had thought that I first needed to get a complete word so to do this  I should use a for loop to iterate through each item in the file, adding it to be the currentWord variable. </p>
  
  <p>Secondly, having got this word/String, I would then do the second step - which was to compare its length with the target ('THRESHOLD') length of 9. If it was greater, then I had found the first word of length greater than or equal to 10, and would return this in a sentence. Otherwise, the loop would continue to iterate?</p>
  
  <p>Here is what I have so far: </p>
  
  <pre><code>    // Write a program that finds the first word in Alice In Wonderland
  // that is longer than a given number of characters.
  
  import java.util.Scanner;
  import java.io.FileReader;
  import java.io.FileNotFoundException;
  
  public class LearningLoops {
  public static void main(String[] args) throws java.io.FileNotFoundException
      {
          Scanner in = new Scanner(new FileReader("aliceInWonderland.txt"));
      String longWord = "";
      boolean found = false;
      final int THRESHOLD = 9;
      int i;
      String currentWord; 
  
      for (i = 0; in.charAt(i) != " "; i++)  {
          currentWord = currentWord + i;
          i++;
      }
  
      while (in != null)  {
          if (currentWord.length() &gt; THRESHOLD) {
              longWord = currentWord; 
          }
      System.out.println("The first long word is: " + longWord);    
          }
      }
  }
  </code></pre>
  
  <p>Is this the right approach? I am stuck and so would be grateful for any help.</p>