Question: I am reading from a file using the code below in java. When the program reads the first word in a line being QUIT. It
I am reading from a file using the code below in java. When the program reads the first word in a line being "QUIT". It is supposed to stop, terminate the program and print "BYE". If the end of the file is reached before finding "QUIT" the program should report that the "QUIT" command was missing and then terminate. Please complete the program below.
Scanner sc = new Scanner(System.in); System.out.println("Enter a file name"); String filename = sc.next(); BufferedReader br = new BufferedReader(new FileReader(filename)); String line; while ((line = br.readLine()) != null) { String[] words = line.split(" "); if (words[0].equals("QUIT")){
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
