Question: JAVA PROGRAMMING I am trying to write a program that will play a game of Mad Libs by taking any .txt file that includes a

JAVA PROGRAMMING

I am trying to write a program that will play a game of Mad Libs by taking any .txt file that includes a story with blanks in the form of placeholders that the user is promptedto replace.

I have my code written, but I have a problem with the askFile method, which takes the input from the user to find the .txt file. It keeps telling me "File Not Found" even though the .txt file is visible in my IDE.

My instructor confirmed the issue is in this particular method, so all you have to worry about is that. She said something about using an if/else statement instead of a while loop?? Here is the method, thank you for your help.

public static File askFile(Scanner lconsole) { System.out.print("file name Input: "); String fileName = lconsole.nextLine(); File lf = new File(fileName); while (!lf.exists()) { System.out.print("File is not found. please try again: "); fileName = lconsole.nextLine(); lf = new File(fileName); } return lf; } 

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 Databases Questions!