This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes buffer whole file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "buffer whole file" Watch "buffer whole file" New topic

buffer whole file

Karsten Daemen

Joined: Nov 19, 2009
Posts: 19

I want to buffer a reasonable small file completely in a BufferedReader, so i can quickly prints it's output to different output streams. So i wrote this:

this throws:

I have now idea what i'm doing wrong. The file is only 2415 bytes long so the casting to integer can't be a problem I think ...

Give me golf clubs, fresh air and a beautiful partner, and you can keep the clubs and the fresh air.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19679

Why not store the contents in a StringBuilder instead?

How To Ask Questions How To Answer Questions
Henry Wong

Joined: Sep 28, 2004
Posts: 18757

The exception means that the mark has been invalidated prior to the reset. And from looking at the source, it looks like the mark is invalidated at the instant that you fill up the buffer; you don't even have to read pass it.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: buffer whole file