This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile's Pointer

 
Val Lee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
srinivas bolloju
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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..!!!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic