Instead of the old io, you can try nio to read a file fragment by fragment in memory, and not by the full file (as suggested in the answers above). You can use the feed to get data from multiple sources.
RandomAccessFile aFile = new RandomAccessFile( "test.txt","r"); FileChannel inChannel = aFile.getChannel(); long fileSize = inChannel.size(); ByteBuffer buffer = ByteBuffer.allocate((int) fileSize); inChannel.read(buffer);
source share