aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RandomAccessFile's Pointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RandomAccessFile Watch "RandomAccessFile New topic
Author

RandomAccessFile's Pointer

Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41

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 SCJP2 1.2<br />====>SCJD
Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41
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

Joined: Jan 23, 2001
Posts: 112
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.


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
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

Joined: Nov 27, 2001
Posts: 41

(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

Joined: Jan 23, 2001
Posts: 112
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..!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RandomAccessFile's Pointer
 
Similar Threads
for loop problem
Database read problem
Reg. casting from Khalid Mughal
If objects can't be passed....
Problem with writing and reading using RandomAccessFile