• 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

RandomAccessFile's Pointer

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The output is:
Pointer is public class at : 0
Pointer is now at 13-------------?
spike is a very good dog.
I think the second output should be 10,but output result is 13.why?
who may tell me? thanks
 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it.
String have a default capacity of 2 characters.
Therefore,the output is 13,not 10.And I am wrong to comprehension of pointer.The pointer is at next writing file's start.
correct me if I wrong.thx
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi val,
before printing out the contents of dat file you are making the pointer position to 0, then printing by saying inout.readUTF. (it should print all the content right??) why are you using 2 readUTF stat's to print the content? im confused. why doesnt the complete content come with only one readUTF?
if i comment ur last sop and modify to include only one readUTF, console shows only "spike is a"
why??
//System.out.println(inout.readUTF() + inout.readUTF());
System.out.println(inout.readUTF());
pls help anybody..
thanks in advance.
 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
API reads:

if output for only one readUTF gives "spike is a" then does that constitute 2 bytes... or will
"spike is a very good dog" since it uses 2 readUTF constitute 4 bytes..?? im confused, am i missing something?
[ July 25, 2002: Message edited by: Valentin Crettaz ]
 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(1)write a block of UTF characters, "000Bspike is a " is written
to story.dat. 000B = 11, it shows length of string("spike is a ").
(2)write another block of UTF characters."000Every good dog." is
written to story.dat. 000E = 14, it shows length of string("very good dog.")
hence,"the first two byte"(API's description) stores length of string.
(3)when file pointer point to 0, the first inout.readUTF() will read the
fisrt block of "spike is a ".
(4)next, pointer point to 13.
(5)inout.readUTF() will read next block of "very good dog."
correct me if I wrong
 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
inout.writeUTF("very good dog.");overwrites inout.writeUTF("good dog."); because pointer was set to that point., but do we need to put as many inout.readUTF() as there are inout.writeUTF's, does this sound a bit odd..!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic