Read binary file with a buffer
I'm trying to read a binary file containing 100.000 different objects. buffering a simple text file with the same content takes only 2MB with a BufferedReader . But reading the binary files takes up to 700 MB and i get OutOfMemory error if I increase the number of objects to read. So how to read the file and get the objects one by one without saturating the memory? Here is the code I'm testing: public static void main(String[] args) throws Exception { int i = 0; String path = "data/file.bin"; InputStream file = new FileInputStream(path); InputStream buffer = new BufferedInputStream(file);