Use java.lang.System.in.read() function in try catch block