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

NX: Reading Database

 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have just started my solution to the Bodgitt and Scarper assigment. After reading some of the suggestions here I am a little confused. People have suggested reading the database using a RandomAccessFile, which sounds like a good way of moving around the database. However the assigment stats that I have to use a DataInputStream and a DataOutputStream. How can I get a DataInputStream to use a RandomAccessFile? As the DataInputStream takes InputStream in is constructor and RandomAccessFile is not an InputStream.
Thanks for your help.
Chris
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
However the assigment stats that I have to use a DataInputStream and a DataOutputStream.

Are you sure your instructions don't state just something like this : "All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes." ? If true :
  • It just concerns the header part of the file
  • Even for the header, the instructions just talk about the format used (for numbers). Formats of RandomAccessFile are 100% compatible with DataInputStream and DataOutputStream classes and implements the same interfaces (DataInput and DataOutput).


  • So you are safe to use it.
    Best,
    Phil.
     
    Chris Harris
    Ranch Hand
    Posts: 231
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    First of all thanks for getting back so quick.
    What are the advantages of using a RandomAccessFile instead of the DataInputStream? As I am able to mark positions in the file and skip bytes with a DataInputStream?
    Chris
     
    Philippe Maquet
    Bartender
    Posts: 1872
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Chris,
    What are the advantages of using a RandomAccessFile instead of the DataInputStream?

    Read/write support. Probably faster too, but I am not sure. But if you use NIO, its getChannel() method will return a readable/writable channel.
    Regards,
    Phil.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic