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
Author

buffer whole file

Karsten Daemen
Greenhorn

Joined: Nov 19, 2009
Posts: 19
Hi!

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
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Why not store the contents in a StringBuilder instead?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18757
    
  40


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.

Henry


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