title: How to know offset of a begining of a line in text file in java?
body: <p>I want to know the offset of every line present in a text file.</p>
  
  <p>For now I have tried,</p>
  
  <pre><code>path=FileSystems.getDefault().getPath(".",filename);
  br=Files.newBufferedReader(path_doc_title_index_path, Charset.defaultCharset());
  int offset=0; //offset of first line.       
  String strline=br.readline();
  offset+=strline.length()+1; //offset of second line
  </code></pre>
  
  <p>In this way I can loop through entire file to know offset of begining of lines in entire text file. But if I use <code>RandomAccessFile</code> to seek through file and access a line using offset calulated by above method then I found myself in the middle of some line. That is it seems that offset are not correct.</p>
  
  <p>What's wrong? Is this method incorrect to calculate offset? Any better and fast methods please?</p>