Import Java.io.File; Import Java.io.FileOutputStream; Import java.io.IOException; Import Java.io.PrintWriter; Import Java.text.SimpleDateFormat; Import Java.util.Date; public class Exceptiondefaulthandler {private final static String Exceptionlogfile = "Textfile/txt/exception.log"; priva Te static Boolean hasfile = false; private static void Generatelogfile () {File File = new file (exceptionlogfile); if (!file.exists ()) {try {FILE.CREATENEWF Ile (); catch (IOException EX) {System.out.println (ex.tostring ());}} HasFile = true; public static void handle (Exception ex) {if (!hasfile) {generatelogfile ();} File File = new file (exceptionlogfile); if (File.canwrite ()) {PrintWriter StreamWriter = null; try {streamwriter = new PrintWriter (new FileOutputStream (file, Tru e)); StreamWriter.Write ("----------------------------------------------------------------"); StreamWriter.Write (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ()); StreamWriter.Write ("----------------------------------------------------------------"); StreamWriter.Write (Systemproperties.newinstance (). Getlineseparator ()); Ex.printstacktrace (StreamWriter); StreamWriter.Write (Systemproperties.newinstance (). Getlineseparator ()); StreamWriter.Close (); The catch (IOException EX) {System.out.println (ex.tostring ());} finally {streamwriter.close ();}} else {System.out.println ("Exception Log file does not have write permission");} }