Posted by: Sourav | July 17, 2014

BufferedReader Example with try catch in Java

 class ReadString {
   public static void main (String[] args) {
      //  prompt the user to enter their name
      System.out.print(“Enter your name: “);
      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(;
      String userName = null;
      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
      try {
         userName = br.readLine();
      } catch (IOException ioe) {
         System.out.println(“IO error trying to read your name!”);
      System.out.println(“Thanks for the name, ” + userName);
}  // end of ReadString class


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: