Question #206966

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.


Expert's answer

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);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS