Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading db-2x1

 
Nathnael Haile-Mickael
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
I am Happy to come back again. This time with the Constracto Assignment.
I need HELP!
Trying to open or read the db file, I tried to write a small programm. Copiling the programm is no problem. But when I try to printout some lines I always get a result: system cannot find the file db-2x1.
Does it mean I have to handel FileNotFoundException? or maybe the file is damaged or something?
Look what i did:
unzipped and copied the db file in Main.jar directory, i even have another copy in the suncertify.db directory. and here is the code i tried to use:

Is the code not good enough?
Thankx
Natty.
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathnael,
Welcome to this forum.
If you don't specify a path for the database file it will look in the current working directory, which is the directory from which the executable jar file is started. If you specify a path for the database file then you have complete control over where you put the database file. Since at some point you will be allowing the user to specify the location of the database file, you will need to handle the FileNotFoundException.
Once you are able to locate the database file the code posted will:
1) skip over the first 8 bytes of the file
2) read the next 4 bytes and interpret the result as an integer representing the number of fields in the database schema
3) read the next 2 bytes and interpret the result as a short representing the magic cookie value
So, why skip the first 8 bytes of the file? If this matches the database file format specified in your assignment instructions then you're fine. It does seems suspicious however that the database file contains 8 unused bytes at the beginning of the database file. What purpose do they serve?
 
Nathnael Haile-Mickael
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NX:
Hi George,
Thanx for the quiq and clear answer. Yes I will do how you said. The 8 bits at the beginning have nothing to say. I was just trying to print out something.
Regards
nathnael.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic