Java Lab 9
Java Lab 9
Create a new Java file (empty Java file), save it to your H: drive, call it lab9
Insert the following code to set up your program:
Be sure to copy the test text files to the location where you saved your Java file
import java.util.Scanner;
import java.io.*;
fileInput.close();
100pt:
reads in from the test file “lab9pt1.txt”, found in the Test Files folder in the shared drive. The program
should print out the contents of the file.
Reads in from the test file “lab9pt2.txt”. The program should print out how many times the following
words appear:
o Hello
o World
o A String that the user inputs
Part 1:
1
2
3
4
5
Part 2:
>>> Ian
Notes:
Be sure to copy the test files into the same directory that your java file is
saved.
Use the following while loop to read in the file, line by line:
while(fileInput.hasNextLine()){
if(line.equals("Ian")){
// Do something…