skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, September 29, 2012

Java program to demonstrate Exception handling

Posted by Admin at 9:17 AM – 0 comments
 

Exceptions handling is the key in Java, that handle run time errors and indicate a calling method whenever an abnormal condition occurred.


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class SimpleExceptionHandling {   

 public static void main(String args[]){     

   try{         

    BufferedReader br = new BufferedReader(new FileReader("xyz"));       
//Buffered reader is a class that reads text from a character-input stream. 
//Here we are creating Buffered reader which generally read request made of a Reader. 
  
    String s = br.readLine();        
//This method read each line of the text and buffer request is stored in the string s.
   System.out.println(s);      
  } 
      catch(FileNotFoundException fne) 
       {
        System.out.println("File not found.");   
//This is the Exception message which is to be displayed if the particular file is not found.
      }
    }
  }


Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger