00:01
Hello students, to provide the code segment is a non -complement because it does not handle the exception properly.
00:08
So, the read data method reads the data from the file but does not handle any potential exceptions that may occur during the file input output operation.
00:18
Specially, the file not found exception and the io exceptions are not properly handled or propagated.
00:25
To make the code complicated, we need to handle the exception properly.
00:30
In this case, that means we are adding a try -catch block to catch the potential exception or declaring the method to throw the io exception.
00:40
So, additionally, we need to ensure that the sensitive data is protected while reading it from the file.
00:47
So, here are the two compliant solutions.
00:50
The first solution is to handle the data with the try -catch block.
01:17
As here in this compliant solution, we add the try and catch blocks to handle the io exceptions that may be thrown during the input output operations.
01:32
So, the catch block locks the error but you can customize the handle based on your application requirements.
01:41
So, whereas in a solution 2, here we are using the try with the resource, try with resources.
01:53
So, where in this compliant solution, where we use the try with a resource statement introducing this in a java 7, it is introduced in a java 7 to automatically close the buffer reader after the block is executed regardless of whether an execution occurs or not.
02:15
This ensures that the resources are properly related.
02:18
These are released even in the case of the exceptions...