Reverse massive text file in Java
file, file-io, java
Solution
If it is uploaded to you and you can get the length at the beginning, you could just create an empty full-sized file up front and write to it starting from the back and working your way to the front using seek
You'd probably want to define a block size (like 1K?) and reverse that much in memory before writing it out to the file.
Problem
What would be the best approach to reverse a large text file that is uploaded asynchronously to a servlet that reverses this file in a scalable and efficient way? - text file can be massive (gigabytes long) - can assume mulitple server/clustered environment to do this in a distributed manner. - open source libraries are encouraged to consider I was thinking of using Java NIO to treat file as an array on disk (so that I don't have to treat the file as a string buffer in memory). Also, I am thinking of using MapReduce to break up the file and process it in separate machines.