I have to create a reader and to catch an exception if a file cannot be read. The code is something like this:
String line;
try {
while ((line = reader.readLine()) != null) {
//DO SOMETHING
}
} catch (IOException e) {
System.out.println("IO operation failed.");
e.printStackTrace();
}
I've got 2 questions:
- Is this code ok?
- How can i make an "unreadable" file to test the code?