IO Package in Java

IO package in Java

In this article we will be discussing about IO package in Java.

Various built-in and pre-defined packages are available in java which helps a programmer in various aspects. These built in packages contains various classes and functionalities.


IO package in java

Packages in Java

Java contains numerous amount of libraries in which various method and classes are stored. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
And in this tutorial, we will be going to discuss about the lang package in java.

IO Package in Java

Classes for the input and output systems via data streams, serialization, and the file system are provided by the package. This guide will walk you through the straightforward and useful methods included in the package.

We can categorize the classes available in are:

  • Input Streams.
  • Output Streams.
  • Error Streams. Input Streams

It is used to read data from the user and is an abstract superclass of the package. Alternatively, we can say that it helps in reading data from files. Using the new keyword, we can construct an object of the input stream class.


InputStream variable_name = new FileInputStream("Textfile_name"); Output Streams output streams writes the data to an output resource and is a superclass of the package and putting the data into the files. By using the new keyword, we can construct an object of the output stream class.


FileOutputStream variable_name = new FileOutputStream("Textfile_name"); Error Streams

We can say Output streams and error streams are somehow identical. Some Compilers display errors in various aspects. The console receives the same output as output streams.
We can take output of the errors with the help of try and catch block.


    // Block of code
catch excepted_error(Exception e){

    // This will print the Exception on the screen

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription