title: Understanding how BufferedReader works in Java
body: <p>Very basic question on how BufferedReader works. Given the string/phrase, I want to find and print it from the file with a lot of text in it.</p>
  
  <p><a href="https://stackoverflow.com/questions/19307481/using-bufferedreader-in-java">using BufferedReader in Java</a> I did some research on this topic and that was the closest result. Not quite addressing my problem though.</p>
  
  <p>So with this information, why does the following code terminate?</p>
  
  <pre><code>public class MainApp {
  
  String line = null;
  String phrase = "eye";
  
  try {
      File file = new File("text.txt");
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
  
      while((line = br.readLine()) != null) {
          if (line.equals(phrase) {
              System.out.println(line);
             }
          }
  
      br.close();
  
  } catch (Exception e) {
     e.printStackTrace();
    }
   }
  }
  </code></pre>
  
  <p><strong>My understanding of how this block should work:</strong></p>
  
  <ul>
  <li>The while loop goes through each line of text until the condition is no longer true</li>
  <li>Each line is stored in the <em>BufferedReader</em></li>
  <li>Loop is working until the condition of  <em>if (line.equals(phrase)</em> is met.</li>
  <li>Prints found phrase.</li>
  </ul>
  
  <p><strong>Why I think it might</strong> <strong><em>not</em></strong> <strong>work:</strong></p>
  
  <ul>
  <li><p>readlines are not stored as strings in the <em>BufferedReader</em> (therefore they can't be compared)</p></li>
  <li><p>faulty logic (most likely the if statement)</p></li>
  </ul>
  
  <p>For the sake of simplicity, let's assume that <strong>"text.txt"</strong> is filled with very long lore ipsum with a single <strong>"eye"</strong> word put somewhere in the middle of it.</p>
  
  <p>Where exactly is the problem? (Don't provide the entire code solution if possible, I'd love to do the coding part myself for the sake of practice).</p>