Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to come one character back in the file stream

 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic