The only two viable choices are to read the whole lot into a memory structure and write it out when done or to use a real database such as hsqldb (I advocate hsqldb because I've used it and it is delightfully easy).
I agree to this comment. These are the best approaches for this problem.
There are databases which does not require a database server. The databases are kept as plain files in your file system and as far as i know you can reach them with JDBC.