title: (JAVA) Comparing a word entered by a user with another word contained in a text file
body: <p>I'd like to verify if my text file already contains a word entered by a user in a textfield. When the user clicks on Validate if the word is already in the file, the user will enter another word. If the word is not in the file, it will add the word. Each line of my file contains one word. I put System.out.println to see what is being printed and it always say that the word does not existe in the file, but it's not true... Can you tell me what's wrong?</p>
  
  <p>Thanks.</p>
  
  <pre><code>class ActionCF implements ActionListener
      {
  
          public void actionPerformed(ActionEvent e)
          {
  
              str = v[0].getText(); 
              BufferedWriter out;
              BufferedReader in;
              String line;
              try 
              {
  
                  out = new BufferedWriter(new FileWriter("D:/File.txt",true));
                  in = new BufferedReader(new FileReader("D:/File.txt"));
  
                  while (( line = in.readLine()) != null)
                  {
                      if ((in.readLine()).contentEquals(str))
                      {
                          System.out.println("Yes");
  
                      }
                      else {
                          System.out.println("No");
  
                          out.newLine();
  
                          out.write(str);
  
                          out.close();
  
                      } 
  
                 }
              }
              catch(IOException t)
              {
                  System.out.println("There was a problem:" + t);
  
              }   
          }
  
      }
  </code></pre>