This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to come one character back in the file stream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to come one character back in the file stream" Watch "how to come one character back in the file stream" New topic
Author

how to come one character back in the file stream

pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
Hi all,
my question is ,I am checking a character from a file using read(),if false I want to go back to the character I just read(if I read again I should get the character I just read) ( I mean move the file marker one character back,is it possisible?
THANKS
pradeep


SCJP1.4,SCBCD
Failure is not when you fall down; its only when you fail to get up again.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

There are two ways you can do this. One is using the "mark()" method of InputStream. You can mark a stream at some point, and then call reset() to reset the stream back to that same point. Not all streams support this, though, and marking before every single-character read may unwieldly.
Another possibility it to use PushbackInputStream or PushbackReader as a wrapper around your file stream. These classes give you the ability to "unread" characters so that they can be read again.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to come one character back in the file stream
 
Similar Threads
how to delete new line characters in java
XML special characters... how to encode them?
How to read a file block by block?
XML into POJO
Adding pdf to a XML file