Input and Output in Java

// By:Team // No Comment

Email this to someonePrint this pageShare on Google+3Share on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon0


Input and Output (I/O):  Input and Output in Java is used to process the input and produce the output based on the input. Java uses the concept of stream to make I/O operations fast. java.io package contains all the classes required for input and output operations.

Stream

A stream is a sequence of data.In Java a stream is composed of bytes. It’s called a stream because it’s like a stream of water that continues to flow.

Three streams are created for us automatically:

  • 1) System.out: standard output stream
  • 2) System.in: standard input stream
  • 3) System.err: standard error

 

Do You Know ?
  • How to write a common data to multiple files using single stream only ?
  • How can we access multiple files by single stream ?
  • How can we improve the performance of Input and Output operation ?
  • How many ways can we read data from the keyboard?
  • What is console class ?
  • How to compress and uncompress the data of a file?

OutputStream

Java application uses an output stream to write data to a destination, it may be a file,an array,peripheral device or socket.

Output in Java

InputStream

Java application uses an input stream to read data from a source, it may be a file,an array,peripheral device or socket.

Input in Java

Java application uses an input stream to read data from a source, it may be a file,an array,peripheral device or socket.


OutputStream class

OutputStream class is an abstract class.It is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink.

Commonly used methods of OutputStream class

Method Description
1) public void write(int)throws IOException: is used to write a byte to the current output stream.
2) public void write(byte[])throws IOException: is used to write an array of byte to the current output stream.
3) public void flush()throws IOException: flushes the current output stream.
4) public void close()throws IOException: is used to close the current output stream.

 


InputStream class

InputStream class is an abstract class.It is the superclass of all classes representing an input stream of bytes.

Commonly used methods of InputStream class

Method Description
1) public abstract int read()throws IOException: reads the next byte of data from the input stream.It returns -1 at the end of file.
2) public int available()throws IOException: returns an estimate of the number of bytes that can be read from the current input stream.
3) public void close()throws IOException: is used to close the current input stream.

 

 

Email this to someonePrint this pageShare on Google+3Share on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon0

About Team

Browse Archived Articles by Team

Related

Sorry. There are no related articles at this time.