title: How do I read from two different places in a file using Buffered IO in Java
body: <p>I'm reading numbers from a file in order to perform a merge sort.  The merge sort must be performed as an external sort as it is a large list of numbers and there is very little main memory available.  I have a working implementation, it uses the BufferedOutputStream to speed up output, and I want to do the same for the input stream.  However, the input must be read from two different places to perform the merge.</p>
  
  <p>Essentially, if I have:</p>
  
  <pre><code>RandomAccessFile File = new RandomAccessFile("File.dat", "rw");
  BufferedInputStream Buffer = new BufferedInputStream(
     new FileInputStream(File.getFD()));
  DataInputStream InputStream = new DataInputStream(Buffer);
  </code></pre>
  
  <p>And I read some integers using <code>InputStream.readInt()</code>, but also want to use <code>File.seek(n)</code> to access other parts of the file, how do I know when the File will next be called for more data and therefore seek back before it is asked for more data.  Alternatively, is it possible to have two RandomAccessFiles, for the same underlying file?</p>