Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Java Programming » IO » Java IO Tutorial
Suryateja Pericherla Categories: IO. No Comments on Java IO Tutorial
Join Our Newsletter - Tips, Contests and Other Updates
Email
Name

Introduction to Java IO

 The Java Input Output (IO) API enables Java programs to read data from and write data to file system or disk and to other devices through a network connection. 

 

This article is a part of our core java tutorial for beginners.

 

The Java I/O API was introduced in the initial version of Java in the mid-90s. In Java SE 1.4, Java NIO was introduced. NIO stands for Non-blocking Input Output. In Java SE 7, NIO2 was released which is basically an improvement of the initial version of NIO.

 

 The package for Java I/O API is java.io. The package for NIO is java.nio and the package for NIO2 is java.nio.file. Java uses the concept of streams for handling input and output. 

 

 A stream is a collection of data or a flow of data . Reading data from an input source requires an input stream and writing data to a target requires an output stream. These streams can be visualized as shown in below figure:

Java IO streams

Text and Binary IO

The Java I/O API defines two kinds of content for a resource:

  1. Character or textual content (ex: text, XML, JSON)
  2. Byte or binary content (ex: image, video)

 

 The base classes related to character streams are Reader and Writer. The base classes related to byte or binary streams are InputStream and OutputStream The differences between character streams and byte streams in Java are given below:

Character Stream Byte Stream
For reading or writing characters to text-based files like XML, HTML, JSON etc. For reading or writing bytes to files like images, videos or files in low-level formats like .exe, .obj, .class, etc.
Deals with 16-bit Unicode characters Deals with bytes (8-bit data)
Streams are called as readers and writers Streams are called as input streams and output streams
Abstract base classes are Reader and Writer Abstract base classes are InputStream and OutputStream

 

For more information, visit the following links:

 

Next let’s look at an introduction to IO in Java.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram