The method shown below, makeJunk generates compile-time error: “unreported exception java.io.IOException; must be caught or declared to be thrown”.

LANGUAGE: Java

CHALLENGE:

The method shown below, makeJunk generates compile-time error:
“unreported exception java.io.IOException; must be caught or declared to be thrown”.
Without changing the behavior (any part of the method body ) and without changing the number of arguments the function takes or its visibility, add the necessary code that will permit this code to compile without error.

Shown:
public void makeJunk(){
new File(“junk”).createNewFile();
}

SOLUTION:

public void makeJunk()throws java.io.IOException {
    new File("junk").createNewFile();
}