Hungry Blue Dev
Hungry Blue Dev

Reputation: 1325

Converting a file to an accessible object

Summary:

I am trying to write a utility program that is based on the information contained in a separate file. The object has to be such that any information on the physical file can be retrieved quickly and can be updated quickly as well.

Details:

The file is a normal ANSI encoded file that is supposed to store definitions of the physical quantities stated in the SI system. What I really want is that I should be able to read and write changes to the definitions whenever required. I'll be using markers(like ":") to get the headings and definitions like:

Length:metre:m:"..length of path traveled by light in vacuum in 
1/299792458th of a second"

and so on.

So in this case is extending RandomAccessFile an option? Will it help me in quick retrieval and syncing of data? Should I use another approach?

Upvotes: 0

Views: 44

Answers (1)

Enno Shioji
Enno Shioji

Reputation: 26882

If you want these things, then I'd advise you to use an embedded ACID database like H2:

  • Guarantee that you don't lose changes that you made
  • Have more than one program access the info

This is because coding up something that correctly does this using low level facilities like RandomAccessFile is quite hard. Storing persistent application state in embedded DBs is commonly done. H2 is probably the most popular among DBs implemented in pure Java.

On how to actually do this, see this: Embedding the Java h2 database programmatically

You prob. want to look at introduction on relational DBs & SQL if you aren't familiar with them.

Upvotes: 1

Related Questions