I see that both are "streams" of data. In that case, why consider them different ? What is the difference really ?
Comment - Please don't close this question. It is the basic kind of stuff that can confound people in an interview.
UPDATE 1 - Everyone seems to say the same thing - you read from IS and write into OS. So, they are basically the same. Like a pipe with water flowing through it. When you use the water from that pipe you call it InputStream and When you pump water into it, its called an output stream. Is it really that trivial ?
UPDATE2 - If the difference is not so "big", then can we have a InAndOutStream instead of having to make code for two classes (InputStream and OutputStream) ?
They are conceptually different
InputStream
you readOutputStream
you writeA stream is data that you access in sequence. You could think of it like a train that you watch from a tunnel entrance so that you can just see one car at a time. Or a stream of widgets coming across a conveyor belt requiring you to tighten a screw on each one before it passes by to the next person down the assembly line who has to pound it with a hammer, and so on. Or sticks floating down a river while you watch from a bridge.
No matter how they work internally, all streams present the same simple model to programs that use them: A stream is a sequence of data. A program uses an input stream to read data from a source, one item at a time:
A program uses an output stream to write data to a destination, one item at time:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With