• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Problem with DataInputStream & DataOutputStream

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody, i am new here, i am working on the URLyBird project, i don't have any problem when reading the database file, in fact i already implemented the read method using DataInputStream and it works fine! my problem begins when i try to implement the update method, it would be easy to solve if i were allow to use the RandomAccessFile, but i think i can not use it, please see my instruction, and tell me if i am obligated to use DataInputStream and DataOutputStream classes, and if so please, please tell how to deal with it when implementing the update method.

My instructions says this:

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.

SCJP
SCJD (in progress)
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, my buddy.

Originally posted by Jose Perozo:
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.



This instruction simply says the headers (the info about the length of each record, the size of each field, etc) use the format of DataInputStream and DataOutputStream. But, we are free to use the RandomAccessFile. And also, remember to use the 8 bit US ASCII character encoding when saving/reading from the database. For example, you can do something like this:

String hotelName = new String(buffer, "US-ASCII");

where buffer is the array of bytes that you just read from the database (using the RandomAccessFile class).
 
Jose Perozo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks! i was very confuse about it. i thought i was forced to use DataInputStream. RandomAccessFile is easier, as everybody usually does, i'll work with it
 
Slime does not pay. Always keep your tiny ad dry.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic