Reputation: 857
I'm looking for thoughts as to what might be the most efficient way to write/read a large (10,000,000+) set of key/value pairs each consisting of a string of arbitrary length followed by a long integer to/from a file in Java. Any suggestions much appreciated.
Upvotes: 2
Views: 7771
Reputation: 857
Using DataInput/OutputStream wrapping a BufferedInput/OuputStream wrapping a FileInput/OutputStream yields acceptable performance for me. Thanks for all the suggestions.
Upvotes: 0
Reputation: 22692
This is what the Properties API is for:
http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html
Notice that there are methods that operate on InputStreams, OuputStreams, PrintStreams, and different kinds of Readers and Writers.
Upvotes: 2
Reputation: 2994
Assuming that key and value are separated by some delimiter.
BufferedReader
's readLine()
method.This is easiest and extremely efficient (if not most) way!
See commons-io wrapper over it :)
Just don't flush() explicitly, let close() method do it :)
Upvotes: 0