Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading an InputStream twice in Java

2,274 views
Skip to first unread message

Jonah

unread,
Oct 7, 2009, 5:11:44 PM10/7/09
to
What is the best way of reading in an InputStream twice in Java? I'm
using the mark(int bytes) and reset() method, but it's flawed as it
limits the number of bytes that can be read before the reset() becomes
invalid.

Gordon V. Cormack

unread,
Oct 7, 2009, 5:27:33 PM10/7/09
to Jonah

Don't read it twice. Save the result in a data structure.

Jonah

unread,
Oct 7, 2009, 5:34:32 PM10/7/09
to

Would a String be sufficient? Then create a Scanner using the String
to "re-read" in the MIPS assembly language? Or would it be better to
use an ArrayList or Hashtable?

Gordon V. Cormack

unread,
Oct 7, 2009, 6:03:16 PM10/7/09
to Jonah

A string scanner would work, but beware string concatenation in
building the string. x + y takes time proportional to the length
of x.

It is probably better to use ArrayList as you suggest.

0 new messages