Question: Do I need to add a try - catch block to throw the FileNotFoundException in this code? If so , what would the finished, compilable

Do I need to add a try-catch block to throw the FileNotFoundException in this code? If so, what would the finished, compilable code for MyCat.java look like?
package cs1302.exceptions;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
/**
* A simpler version of the Unix cat command.
*/
public class MyCat {
/**
* Entry point for the application. Exactly zero or one command-line arguments are expected.
* If a filename is given as an argument, then the program should print the contents of that
* file to standard output. If a single dash (i.e.,"-") is given as an argument, then
* the program should print the contents of standard input.
*
* @param args the command-line arguments
*/
public static void main(String[] args){
String filename = args[0];
if (filename.equals("-")){
Printer.printStdInLines();
} else {
File file = new File(filename);
Printer.printFileLines(file);
}// if
}// main
}// MyCat

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!