title: Continuous File reading
body: <p>I have very different scenario in my application. I need to read some text file and do some some work on that.</p>
  
  <p>Actually what I want is,  when I reach to the end of line,  my file reading cursor in Java will stop there and wait until the new line append in the text file. Actually the file which I am reading is a real time logs which are generated by the server, the log will generate after every one second.</p>
  
  <p>So I want that my file reading process will never end, it keep on reading file as new data comes in the file.</p>
  
  <p>I have written this code,</p>
  
  <pre><code> try {
          Scanner sc = new Scanner(file);
  
          while (sc.hasNextLine()) 
          {
              String i = sc.nextLine();
  
              processLine(i);    //a method which do some stuff on the line which i read
              if(thread==1)
              {
               System.out.print("After loop in the file"); //just for printing
              }
              while(!(sc.hasNextLine()))     //in the loop until new line comes 
                  {
                      System.out.println("End of file");
                      Thread.sleep(100000);
                      System.out.println("Thread is waiting");
                      thread++;
                  }
              if(thread==1)
                  {   
                      System.out.println("OUt of the thread");
                  }
     //System.out.println(i);
          }
          sc.close();
          System.out.println("Last time stemp is "+TimeStem);
          System.out.println("Previous Time Stemp is "+Previous_time);
      } 
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>This is my code, I think my program will remain in the second while loop when end of file reach and when file append it start reading file again. But it's not happening, when end of file is reached, my program wait for some second but never read the next line which is appended in the file.</p>