What Are Streams?

   

Most computer programs accept some form of input and generate some type of output. That is, after all, basically what a computer is useful for. Every computer language must have a way of dealing with input and output; otherwise , it would be impossible to write a useful program. The input could come from a file on disk, data sent over the network, or even another program. This is true of the output as well.

Most information used within a computer program flows from the input source through the computer program and then possibly on to an output destination. This idea of data flow leads to the term stream. A stream is nothing more than a flow of data through some channel. Input streams direct data from the outside world ”a keyboard or a file, for instance ”into the computer. Output streams direct data toward output devices, such as the computer screen, file, or even another computer program. Because streams are general in nature, a basic stream does not specifically define which devices the data flows from or to. Just like a wire carrying electricity that is being routed to a light bulb, TV, or dishwasher; a basic input or output stream can be directed to or from many different sources.

The Java API features a rich set of classes that represents everything from a general input or output stream to a sophisticated stream that uses data from a random-access file. In this chapter, you learn how to use these important classes.

In general, there are streams for a variety of sources including access to common file system functions (such as file and directory creation, removal, and renaming, as well as directory listing). The input and output streams can be connected to files, network sockets, or internal memory buffers.

The java.io package also contains a number of stream filters that enable you to access stream data in a variety of different formats. You can also create your own filters to add more functionality to the Java programming language.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net