title: How to print lines from a file that contain a specific word using java?
body: <p>How to print lines from a file that contain a specific word using java ?</p>
  
  <p>Want to create a simple utility that allows to find a word in a file and prints the complete line in which given word is present.</p>
  
  <p>I have done this much to count the occurence but don't knoe hoe to print the line containing it...</p>
  
  <pre><code>      import java.io.*;
  
         public class SearchThe {
            public static void main(String args[]) 
             {
               try 
                {
                  String stringSearch = "System";
  
                   BufferedReader bf = new BufferedReader(new FileReader("d:/sh/test.txt"));
  
           int linecount = 0;
              String line;
  
          System.out.println("Searching for " + stringSearch + " in file...");
  
          while (( line = bf.readLine()) != null)
          {
              linecount++;
              int indexfound = line.indexOf(stringSearch);
  
              if (indexfound &gt; -1) 
              {
                  System.out.println("Word is at position " + indexfound + " on line " + linecount);
              }
          }
          bf.close();
      }
      catch (IOException e) 
      {
          System.out.println("IO Error Occurred: " + e.toString());
      }
  }
  </code></pre>
  
  <p>}</p>