Re: Interactive tracing ...
Mark Space wrote:
Andreas Leitgeb wrote:
Especially finding the right stacking of streams and readers is something
that would have taken me a lot of time to get right - Thanks for
saving me
that work! :-)
This is perennial complaint of mine as well.
In general, the Stream classes are older, and there were some
deficiencies found. So therefore the Reader and Writer classes were
introduced.
The Stream classes may be slightly older, in that it took all the way until
Java 1.1 [1] until they introduced Readers and Writers, but by no means does
that mean that Streams are deficient or no longer relevant. (What
"deficiencies" were found in Streams, anyway?)
The real difference, and the important one, is that Streams handle bytes and
Readers/Writers handle characters and their encodings. If you aren't handling
characters, do NOT use Readers and Writers. Streams are most emphatically not
obsolete.
To bridge the two, use InputStreamReader and OutputStreamWriter. These
both go from an older style IO (the Stream) to the newer version
(Readers and Writers), just what you would expect for a class system
that's been upgraded.
It's not about "upgrades", it's about whether you're processing binary or text
data.
Check out this tutorial, paying particular attention to the the section
on Character Streams. That's where the important bit is.
<http://java.sun.com/docs/books/tutorial/essential/io/index.html>
You'll note that there's nothing in there about Streams' "deficiencies" or
about Readers/Writers substituting for Streams.
After that, you just look up which IO Stream does what you want, which
Reader or Writer gives you the final result you want, and put those two
together with an IO Stream Reader/writer object if needed. Notice that
this is just what Knute has done.
If you are reading character streams.
Sometimes, you put a BufferedReader or -Writer in between a outer
Reader/Writer and the IO Stream Reader/Writer. These last two
paragraphs will get you 90% of what you need from Java IO.
Or you put the BufferedReader/Writer on top, not the middle.
P.S. _Learning Java_ by O'Reilly. It goes into all this. ;-)
Again, it's Streams for binary data, Readers and Writers for encoded character
data, nothing to do with newer or older.
[1] I'll bet that very nearly all the Java programmers reading this post
learned Java at or after version 1.1. I myself started learning Java during
1.1 and started practicing it professionally with version 1.2. By that time,
Hashtable and Vector were already obsolete and the Reader and Writer classes
were well established.
--
Lew