Answer to Question #206966 in Java | JSP | JSF for Cynthia

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.


1
Expert's answer
2021-06-15T01:28:57-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS