title: Detecting empty line while reading file with Java
body: <p>So I have a problem with reading a file. My code is simple with using BufferedRead. My text consist of header and body like below:</p>
  
  <pre><code>&gt;Header1
  This is body1 line1
  This is body1 line2
  &gt;Header2
  This is body2 line1
  This is body2 line2
  This is body2 line3
  This is body2 line4
  </code></pre>
  
  <p>So basically, I check each line whether it is header or not and then process it according to the procedure for header and body.</p>
  
  <pre><code>try{
     FileReader file = new FileReader("file1.txt");
     BufferedReader br = new BufferedReader(file);
     String line;
     while((line=br.readLine()!=null &amp;&amp; line.length()&gt;0){
        if(checkHeader(line)){
           ProcessHeader(line);
        }else{
           ProcessBody(line);
        }
     }
  }
  </code></pre>
  
  <p>The problem is, I realize that because this is a downloadable fie from a server, sometimes the file has blank line randomly. For example, after 10 Header and body, there is blank space. The next blank space maybe after 15 header/body. It will become like below:</p>
  
  <pre><code>&gt;Header1
  This is body1 line1
  This is body1 line2
  &gt;Header2
  This is body2 line1
  This is body2 line2
  This is body2 line3
  This is body2 line4
  .&lt;not blank line&gt;
  .&lt;not blank line&gt;
  .&lt;not blank line&gt;
  &gt;Header10
  Body10 line1
  Body10 line2
  
  &gt;Header11
  Body11 line1
  Body11 line2
  .&lt;not blank line&gt;
  .&lt;not blank line&gt;
  .&lt;not blank line&gt;
  &gt;Header 25
  Body25 line1
  Body25line2
  
  &gt;Header 26
  .&lt;not blank line&gt;
  .&lt;not blank line&gt;
  ...
  </code></pre>
  
  <p>How can I detect such blank line because currently, my while loop will stop after it finds a blank line? How can I check for the end of file? Thank you.</p>