« back

Some Differences Between Writers and Streams

11 Dec 2012

Heck, just what are Writers and Streams?

Since starting work on my Echo Server in Clojure, I've been dealing more with standard streams and writers. The whole concept was pretty new to me and I found that you could not just use them all interchangeably. This will be by no means exhaustive but a look at what some of the basic differences are. Here goes...

So what are streams? They are a way for us to allow our program to interact with the outside world. They give us the ability to handle input and output also known as I/O. The abstractions of input and output in the java world are referred to as streams. One thing that I found out that is pretty important is that there are two major differences in types of data. There is data that computers can read and there is data that humans read. The data streams that are for computers are called byte streams. The data streams for humans are called character streams.

Objects that read or write in byte streams are part of the InputStream and OutputStream classes, respectively. Objects that deal with human readable data are part of the Reader or Writer class.

That is pretty much the key take away when you are working with input and output. There are other classes that wrap those classes to provide more functionality such as PrintWriter, but the information I provided you is the meat and potatoes.

Now lick your plate clean and go work with streams.

comments powered by Disqus