All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
But it has a lot of troubles such as updating the data file. I must delete the file and rebuild it frequently. It is not efficient.
Now I hava a new idea. Can I use the java.io.RandomAccessFile object according to Sun's requirement?
Or anyone has a better idea to implement it?
This message was edited 1 time. Last update was at by Xin Gang Sun
Xin Gang Sun
boolean scjp_6 = true;
boolean scjd_URLyBird = willBeTrue();
//I hope!
Tahir Abbas
Ranch Hand
Joined: May 05, 2007
Posts: 44
posted
0
I also used java.io.RandomAccessFile to deal with the database. In database first there is information about database e.g; magic cookie value, number of fields etc then the record data in database starts. Data file section in instruction file will be very useful for dealing with database. If you search on this forum you'll get many useful threads regarding your problem.
Xin Gang Sun
Greenhorn
Joined: Sep 03, 2009
Posts: 17
posted
0
Thank you! Using RandomAccessFile make the code clear. I can just apply my mind to the concurrency.
Anne Crace
Ranch Hand
Joined: Aug 29, 2005
Posts: 223
posted
0
I can just apply my mind to the concurrency.
Hello Xin,
I wouldn't worry about concurrency at this time. That is usually one of the last things you will do. Deal with reading the database first. You can use a synchronized block for your reads and writes but this is something that can easily be added later when you deal with locking. You need to do a little more than add a synchronized block to accomplish the locking, though! Lots of good information on this forum to help you with that when the time comes!
SCJP, SCJD
Georgiana Lungu
Ranch Hand
Joined: May 17, 2010
Posts: 34
posted
0
I have seen this post and is targeting one of my actual problems too. So, my question is, may I use RandomAccessFile although my specification states:
"All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII. " ?
Georgiana Lungu wrote:So, my question is, may I use RandomAccessFile...
Oh yes, absolutely. If you look at the RandomAccessFile API, you can verify that it implements DataInput and DataOutput interfaces, so it can be used to deal with the database file.