title: Binary search in a sorted (memory-mapped ?) file in Java
body: <p>I am struggling to port a Perl program to Java, and learning Java as I go. A central component of the original program is a <a href="http://search.cpan.org/~jfreeman/File-SortedSeek-0.015/lib/File/SortedSeek.pm" rel="noreferrer">Perl module</a> that does string prefix lookups in a +500 GB sorted text file using binary search 
  (essentially, "seek" to a byte offset in the middle of the file, backtrack to nearest newline, compare line prefix with the search string, "seek" to half/double that byte offset, repeat until found...)</p>
  
  <p>I have experimented with several database solutions but found that nothing beats this in sheer lookup speed with data sets of this size. Do you know of any existing Java library that implements such functionality? Failing that, could you point me to some idiomatic example code that does random access reads in text files?</p>
  
  <p>Alternatively, I am not familiar with the new (?) Java I/O libraries but would it be an option to memory-map the 500 GB text file (I'm on a 64-bit machine with memory to spare) and do binary search on the memory-mapped byte array? I would be very interested to hear any experiences you have to share about this and similar problems.</p>