2

I am using a dataoutput/datainputStream to make a binary Tree over a file,reading a 50000 lines .csv file to build it.

Initially i thought to achieve this with the RandomAccesFile class, but it has serious permormance issues (it's very slow on multiple read/write operations with small amounts of data). I achieved the seek performance when read using:

public void seek(long bytes) throws IOException{
    this.dataInputStream.reset();
    if(bytes>=0)
    this.dataInputStream.skip(bytes);       
}

Is possible to achieve write somewhere in the file using DataOutputStream, like RandomAccessFile does?.

Thank you for your support

  • No. I suggest you use a `MappedByteBuffer`. NB The data streams don't perform any better than `RandomAccessFile`, unless you have buffered streams underneath them. – user207421 Jun 21 '17 at 00:32
  • thanks for answering. I do have a bufferedInputStream under the DatainputStream. And It allows me to make th seek operation on reading. Do you know some way in wich i can perform seek functionallity, in order to write anywhere in the file?. Need Something better than RandomAccess, because it's terribly slow while addin a new element to the tree – Bayron Daniel Mendoza Tovar Jun 21 '17 at 03:56
  • It only allows you to make the seek operation because you must be using `mark()`, and you must also have a `BufferedInputStream` buffer the size of the file. This is extremely wasteful of space and it raises major concurrency concerns. I have already made my suggestion. – user207421 Jun 21 '17 at 05:53
  • Thank you for your support!!. I will edit this question with the solution, with a `MappedByteBuffer` that has the most commonly `RandomAccessFile` methods, and performs significantly faster – Bayron Daniel Mendoza Tovar Jun 22 '17 at 01:52

0 Answers0