IOException with BufferedReader class

IOException is on run time input output exception handler, when we use java.io.* package’s classes that time we have to use IOException for handling error.

BufferedReader is one inbuilt class. BufferedReader class must be in java.io.* package so we have to import that package in our program starting.

In this program, we will see how to handle run time error without try/catch block.

Example on IOException

import java.io.*;        

class Exc10

{

            public static void main(String args[]) throws IOException

            {

                        String username = “” , password = “”;

 

InputStreamReader ir = new InputStreamReader(System.in);      

                        BufferedReader br = new BufferedReader(ir);

 

                        System.out.println(“Enter Username : “);

                        username = br.readLine(); // Method -> Return String value

                        System.out.println(“Enter Password : “);

                        password = br.readLine(); // Method -> Return String value

 

                        System.out.println(“Username  : ” + username);

                        System.out.println(“Password  : ” + password);   

            }

}          

Output:

Enter Username: demouser

Enter Password: 123456

Username: demouser

Password: 123456

 

In this program, you can’t understand throws over try/catch. For that we have to watch this video.

 

Video available on YouTube now.

 


[sbscrbr_form]

If you have query about this blog, you can directly post comment or subscribe on website.


Earn money online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

172total visits,5visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

EmailEmail
PrintPrint