Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #658

Re: Using mark and reset on BufferReader, but with unknown file length

From Lothar Kimmeringer <news200709@kimmeringer.de>
Newsgroups comp.lang.java.help
Subject Re: Using mark and reset on BufferReader, but with unknown file length
Date 2011-04-26 09:50 +0200
Organization Organization?! Only chaos here!
Message-ID <4m204ajgp3vh.dlg@kimmeringer.de> (permalink)
References <87mxjhrz10.fsf@merciadriluca-station.MERCIADRILUCA>

Show all headers | View raw


Hi,

Merciadri Luca wrote:

> -----BEGIN PGP SIGNED MESSAGE-----

it's uncommon to sign news postings.

> For some reasons that come out of the scope of this discussion, I need
> to read a file twice. I would prefer not to do
> 
> BufferedReader inputFile = new BufferedReader(new
> FileReader(inputFilename));
> 
> twice, and, as a result, I would like to use my preceding
> BufferedReader to read the file again, a second time.

Why not using a RandomAccessFile instead?

> That is, I first read the file, then close it, then need to re-read
> it. To re-read it, I would like to use reset and mark methods, defined
> over BufferedReader objects. The problem is that mark obliges me to
> give a number of characters:

The reason is, that BufferedReader is creating an internal array
of that size to store the characters into. So setting it to the
size of the file you can also just read in the complete file in
an array for yourself and work on that so many times you want. If
the file is too big for the memory you have, you will run into
problems (of course).


Regards, Lothar
-- 
Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

Back to comp.lang.java.help | Previous | NextPrevious in thread | Find similar


Thread

Using mark and reset on BufferReader, but with unknown file length Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-23 13:24 +0200
  Re: Using mark and reset on BufferReader, but with unknown file length Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-23 08:52 -0400
  Re: Using mark and reset on BufferReader, but with unknown file length Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-04-26 09:50 +0200

csiph-web