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. } } }