Java Tutorial - Java Script :
The procedure for using either a byte stream or a character stream in Java is largely the same. Before you start working with the specifics of the java.io classes, it’s useful to walk through the process of creating and using streams. For an input stream, the first step is to create an object associated with the data source.For example, if the source is a file on your hard drive, a FileInputStream object could be associated with this file. After you have a stream object, you can read information from that stream by using one of the object’s methods. FileInputStream includes a read() method that returns a byte read from the file.
When you’re finished reading information from the stream, you call the close() method to indicate that you’re finished using the stream. For an output stream, you begin by creating an object associated with the data’s destination. One such object can be created from the BufferedWriter class, which represents an efficient way to create text files. The write() method is the simplest way to send information to the output stream’s destination.For instance, a BufferedWriter write() method can send individual characters to an output stream. As with input streams, the close() method is called on an output stream when you have no more information to send.