System.in.read(), why use anything else?
the in() method of the class System is an InputStream (abstract class). it does have an instantiation of read() and it reads bytes. So why use something like StringReader() or ByteArrayInputReader(), wher you'd have to open up a stream and everything. To me it seems like this abstract class has quite a bit of functionality already. All the other subclasses that extends the InputStream class, is nice, but for just reading the command line is there any need to use anything other than just the default in.read()? Thanks.I think I am understanding streams a little better now.
> the in() method of the class System is an InputStream
> (abstract class). it does have an instantiation of
> read() and it reads bytes. So why use something like
> StringReader() or ByteArrayInputReader(), wher you'd
> have to open up a stream and everything. To me it
> seems like this abstract class has quite a bit of
> functionality already. All the other subclasses that
> extends the InputStream class, is nice, but for just
> reading the command line is there any need to use
> anything other than just the default in.read()?
> Thanks.I think I am understanding streams a little
> better now.
Here's a table from Sun's Java tutorial describing what some of these streams do and when you might want to use them:
http://java.sun.com/docs/books/tutorial/essential/io/datasinks.html
You could read the command line that way, but likewise you could eat peas with a toothpick. It works, but a more capable tool like a spoon usually works better. That's why you'd use a BufferedReader or something like that.