-5

What changes do I need to make in the code If I remove the line "throws IOException"??

import java.io.*;
class Buffered_class{
    public static void main(String[] args) 
                    throws IOException // remove this line 
    {
        char c;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter characters, 'q' to quit");
        do{
           c= (char)br.read();
           System.out.println(" you entered : " + c );
       }while(c !='q'); 
    }
}   
Prabhakaran Ramaswamy
  • 25,706
  • 10
  • 57
  • 64
brijesh
  • 19

1 Answers1

2

You need to catch the exception

import java.io.*;    
class Buffered_class{
    public static void main(String[] args)
    {
       char c;
       try{
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           System.out.print("Enter characters, 'q' to quit");        
           do{
               c= (char)br.read();
               System.out.println(" you entered : " + c );

           }while(c !='q'); 
       }catch(IOException e){
             // do something
       }finally{
           br.close();
   }
}