• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Reading Database

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic