File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mark() in IO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mark() in IO" Watch "mark() in IO" New topic
Author

mark() in IO

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219

Test.txt has a text "TEST"
I thought reset() will position the cursor to the previous position. It always positon to first character of the file.


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

You're code is working correctly... I think you have the meaning of .mark(int) wrong:

Here's the API for InputStream.mark()

mark
public void mark(int´┐Żreadlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.
The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

This little chunk of code might help you understand things a bit better:


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Thanks Jessica,
How do you say mark(10) marks next character?
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Thiru Thangavelu:
Thanks Jessica,
How do you say mark(10) marks next character?

Read the API -- the int '10' doesn't have anything to do with which character gets marked. .mark(int) always marks the next character in the stream. The int parameter is the read limit -- it tells the input stream to allow that many bytes to be read before the mark position gets invalidated.
So if you called stream.mark(2) and then read in 3 characters -- that mark would no longer be valid -- because you passed the readlimit. -- I believe if you call .reset() on an invalid mark, you will get an IOException.
Sri Wunnava
Greenhorn

Joined: Jun 19, 2002
Posts: 2
Hi Thiru..
I am seeing ur postings from quite long time.. when ur going to take test.. can u give me some tips even I am planning to take test..
Thanks,
Sri


Sri
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Sri Wunnava:
can u give me some tips even I am planning to take test..

Sri-
Check out the Forum FAQ. It's got all sorts of helpful links and tips.
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Sri,
That's a nice link. I am planning to take this week itself. You can get lot of mock exams in the web.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mark() in IO