IO Streams Overview Java


Data can be stored on a computer system, as per the code requirements, in two ways, either permanently or temporarily. Temporary storage can be accomplished by storing the data in datastructures or instance variables. The data is temporary because it is stored in RAM. For a permanent storage, the data should be stored on the hard disk either in the form of database tables or files. This tutorial is concerned with I/O streams used to write data to a file and later read from the file.

IO Streams Overview Java

There comes two entities – a source and a destination. Source is that from where data is read and the destination is that one to where data is written. The source and destination need not be a file only; it can be a socket or keyboard input etc. To do the job of reading and writing, there comes two types of streams – input streams and output streams. An input stream job is to read from the source and the output stream job is to write to the destination. That is, in the program, it is necessary to link the input stream object to the soruce and the output stream object to the destination.

I/O streams are carriers of data from one place to another. The input stream carries data from the source and places it temporarily in a variable (like int k or String str etc.) in the process (program). The output stream takes the data from the variable and writes to the destination. The variable works like a temporary buffer between input stream and output stream.

IO Streams Overview Java
IO Streams Overview Java

It is clear from the above figure, the input stream reads from the soruce and puts in the buffer (actually in programming, in a temporary variable, shown later). The output stream takes from the memory and writes to the destination.

All the classes needed to do with reading and writing (like file copying) are placed in the package java.io by the designers. All the I/O streams do the file reading or writing sequentially (means, one byte after another from start to the end of file). It can be done at random also. For this another class exists – RandomAccessFile. The java.io package also includes another class, File, to know the properties of a file like the file has read permission or write permission etc.

14 thoughts on “IO Streams Overview Java”

  1. manisha srivastava

    sir, where(in which folder or file) we store the created files by io steram and how to read from a specified file

    1. The created files are stored in the current directory (the directory where you write the source code and compile).

      If you would like to be created in a different directory, give the path as follows.

      FileInputStream fis = new FileInputStream(“d:/snrao/corejava/def.txt”);

      Do not use backward slash. Still if it does not work with you, I give another different way.

Leave a Comment

Your email address will not be published.