Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use Mark and reset for inputstream ?  RSS feed

 
Joseph Tsui
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to reuse the BufferedInputStream, it throws some error. How should I use the mark and reset method ? thanks in advance




java.io.IOException: Mark invalid
at java.io.BufferedReader.reset(BufferedReader.java:485)
at TestCookie.main(TestCookie.java:32)

[Nitesh: Added Code Tags.]
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the Java API doc for BufferedInputStream, you'll see the argument you pass to mark() is:

So, according to your code, after you read 50 bytes, the mark you have set is invalid.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!