A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
I/O and Streams
buffer whole file
Joined: Nov 19, 2009
Feb 27, 2010 06:20:21
I want to buffer a reasonable small file completely in a
, so i can quickly prints it's output to different output streams. So i wrote this:
File file =new File("FBookMaker.html"); buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file)),(int) file.length()); // Mark it at the begin of the buffer, so i can start all over with buffer.reset(). buffer.mark((int) file.length()-1);
java.io.IOException: Mark invalid at java.io.BufferedReader.reset(BufferedReader.java:485)
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.
Joined: Oct 27, 2005
Feb 28, 2010 08:47:16
Why not store the contents in a
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions
How To Answer Questions
Joined: Sep 28, 2004
Feb 28, 2010 09:11:50
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.
Java Threads, 3rd Edition
Jini in a Nutshell
Java Gems (contributor)
I agree. Here's the link:
subject: buffer whole file
Opening a PDF
Reading a file using NIO
Size problem in http message?
Is there an efficient way to read a text file into a string?
Out of Memory exception
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014