aspose file tools*
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
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 ...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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: 18990
    
  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)
 
 
subject: buffer whole file