title: How to identify a string and print line in a file in java?
body: <p>I am Java beginner and I am trying to find a word in the file and print out the line where it exists.<br/> My file looks like:</p>
  
  <pre>
  dog  one 100.11
  cat two 200.22
  doggg  four 400.44 
  </pre>
  
  <p>And if I input "dog", the output should be </p>
  
  <blockquote>
    <p>dog  one 100.11</p>
  </blockquote>
  
  <p>But currently I have an error the word is not found.
  <br/>Please Help! Thanks!</p>
  
  <pre><code>File file = new File("G:\\Eclipse\\src\\test.txt");
  Scanner s = new Scanner(file);
  Scanner input = new Scanner(System.in);
  System.out.println("Input:");
  String name = input.next();
  while (s.hasNext()) {
    String line = s.nextLine();
    String name = s.next();
    if (name.equals(name)) {
      System.out.println(line);
    }
  }
  </code></pre>