Sometimes you write data to a file instead of the computer screen. Under Unix and DOS you can sometimes do this using the redirection operators < and >. However sometimes you need a more fine-grained approach that writes only certain data to a file while still putting other data on the screen. Or you may need access to multiple files simultaneously. Or maybe you want to query the user for input rather than accepting it all on the command line. Or maybe you want to read data out of a file that’s in a particular format. In Java all these methods take place as streams.
Streams are a big topic in Java and later we’ll devote an entire chapter to them. For now we want to cover just the very basics that let you write files, read files and communicate with the user. In fact the
System.out.println() statement we’ve been using all along is an implementation of Streams.