Amend or edit given code PaySlip.java so that if the input file does not exist, the program handles the FileNotFoundException, outputs an appropriate message, and terminates normally.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class PaySlip {
public void readFile(String fileName){
try(Scanner in = new Scanner(new File(fileName))){
while(in.hasNextLine()){
in.nextLine();
}
}catch (FileNotFoundException e){
System.out.println(e.getMessage());
System.exit(0);
}
}
}
Comments
Leave a comment