I/O in java

Java I/O is an API which is used to read and write data (Input and Output) and it is located in package called java.io.The Java IO package is primarily focused on input and output to files, network streams, internal memory buffers etc. or in sample terms we can say it perform file handling in java.

Java I/O API is mostly concerned for reading the raw data from from a source and writing the raw data to a destination. What could be these source and destination?

  • Files
  • pipes
  • Network connection
  • System.in, System.out, System.error
  • In memory-Buffers (e.g. arrays)

Streams:

A stream is conceptually endless flow of data. It could be in byte form or character form. We can either read from a Stream and write to a Stream

Program needs InputStream or Reader to read the data from source and requires OutputStream or writer to write the data to some destination.

In java, we mostly see 3 kinds of stream as mentioned below.

  1. System.in: standard input stream (read data from console)
  2. System.out: standard output stream (Write data to console)
  3. System.err: standard error stream (Write data to console)

These streams are attached with the console. Let’s understand these with examples.

Read input from console.
int i = System.in.read();

Write output and error to Console.
System.out.println(“Output”);
System.err.println(“Error”);

I/O overview

Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.

 

Different ways to reverse String in java
InputStream and OutputStream in java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

1 Response

  1. August 8, 2015

    […] In this post , we will look at what is InputStream and OutputStream in java? In the previous post, we have seen I/O overview. […]

Leave a Reply

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