How do I sort very large files

That isn’t exactly a Java problem. You need to look into an efficient algorithm for sorting data that isn’t completely read into memory. A few adaptations to Merge-Sort can achieve this.

Take a look at this:
http://en.wikipedia.org/wiki/Merge_sort

and:
http://en.wikipedia.org/wiki/External_sorting

Basically the idea here is to break the file into smaller pieces, sort them (either with merge sort or another method), and then use the Merge from merge-sort to create the new, sorted file.

Leave a Comment