Home Java Example Java Io What is Java I/O?
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

What is Java I/O?

Advertisement
Here, you will know several interfaces provided by the java.io package.

What is Java I/O?

     

Introduction

The Java Input/Output (I/O) is a part of java.io package. The java.io package contains a relatively large number of classes that support  input and output operations. The classes in the package are primarily abstract classes and stream-oriented that define methods and subclasses which allow bytes to be read from and written to files or other input and output sources. The InputStream and OutputStream  are central classes in the package which are used for reading from and writing to byte streams, respectively.

The java.io package can be categories along with its stream classes in a hierarchy structure shown below:

InputStream:

The InputStream class is used for reading the data such as a byte and array of bytes from an input source. An input source can be a file, a string, or memory that may contain the data. It is an abstract class that defines the programming interface for all input streams that are inherited from it. An input stream is automatically opened when you create it. You cans explicitly close a stream with the close( ) method, or let it be closed implicitly when the object is found as a garbage.

The subclasses inherited from the InputStream class can be seen in a hierarchy manner shown below:

InputStream is inherited from the Object class. Each class of the InputStreams provided by the java.io package is intended for a different purpose.

 

OutputStream:

The OutputStream class is a sibling to InputStream that is used for writing byte and array of bytes to an output source. Similar to input sources, an output source can be anything such as a file, a string, or memory containing the data. Like an input stream, an output stream is automatically opened when you create it. You can explicitly close an output stream with the close( ) method, or let it be closed implicitly when the object is garbage collected.

The classes inherited from the OutputStream class can be seen in a hierarchy structure shown below:

OutputStream is also inherited from the Object class. Each class of the OutputStreams provided by the java.io package is intended for a different purpose.

How Files and Streams Work:

Java uses streams to handle I/O operations through which the data is flowed from one location to another. For example, an InputStream can flow the data from a disk file to the  internal memory and an OutputStream can flow the data from the internal memory to a disk file. The disk-file may be a text file or a binary file. When we work with a text file,  we use a character stream where one character is treated as per byte on disk. When we work with a binary file,  we use a binary stream.

The working process of the I/O streams can be shown in the given diagram.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 16, 2007

Related Tutorials

Ask Questions?    Discuss: What is Java I/O?   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Preethimalie Kahandawela
April 11, 2011
java i/o

Please send me as much as possible questions regarding java input output
Bubi
September 22, 2011
OfeQRybnUDpf

This site is like a cslarsoom, except I don't hate it. lol
Anand
October 12, 2011
java

what io.*
nicholus
November 17, 2011
internet programming

i will like you guys to explain and give examples after explaining.but otherwise your good source of information when one needs one
william
May 26, 2014
kep kep kep

i like turtles
DMCA.com