Write Java code that attempts to call a method named bootUp() which takes a String parameter and returns an integer value. The String parameter should be read from a file named "bootConfig.txt" and is the only value in the file. If a BootUpException is thrown, print the Exception object's message. If a DriverException occurs, call the reboot() method and rethrow the original DriverException object. If any other type of Exception is thrown, print a generic error message to the console. This code should always invoke the releaseAllLockedResources() method, regardless of any issues. If the bootUp() call is successful, the returned value should be output to a file named "bootLog.txt" with the String literal "Boot Status: " before it. Try-with-resources should be used for this problem.
I have given you the code snippet for the specifications in the question. But you should have all the methods and user-defined exception classes mentioned in the question.
try(Scanner in = new Scanner(new File("bootConfig.txt"))){
String str = in.nextLine();
int ret = bootUp(str);
try(PrintWriter out = new PrintWriter(new
File("bootLog.txt"))){
out.println("Boot Status: " +
ret);
}
}
catch(BootUpException be) {
System.out.println(be.getMessage());
}
catch(DriverException de) {
reboot();
throw de;
}
catch (Exception e) {
System.out.println("An error occured");
}
finally {
releaseAllLockedResources();
}
Get Answers For Free
Most questions answered within 1 hours.