0

In java, what is the fastest way to read a huge binary file into int[]. I saw this solution

Fastest way to read huge number of int from binary file

But there is two solutions, and I don't know which is better. Also they seem to give a fixed maximum size for the int[], but how can I do it with a variable size? Like how can I set it to fit the amount of data in the binary exactly. Is there a way to know how many ints are there in the file?

Thanks

Community
  • 1
  • 1
omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

0

You could have some variables to calculate the time in both solutions, then compare the two.

while (bytesRead != -1) {
  double start = System.currentTimeMillis();
   while(doingstuff){}
  double timeTaken = System.currentTimeMillis() - start;
}

As for the array, you could use a arraylist which is expandable.

ArrayList<int> binary = new ArrayList<int>();
binary.add(stuff);
kristianp
  • 5,496
  • 37
  • 56
Psicoses
  • 3
  • 3