File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  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: 18500
    
  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
 
Similar Threads
Out of Memory exception
Reading a file using NIO
Opening a PDF
Is there an efficient way to read a text file into a string?
Size problem in http message?