Completed
lab is due by: tomorrow but see DELIVERABLES
below
Use the java program
Lab3.java as your base. Be sure to fill
in your name in the header.
Part 1 - Manipulating files.
1.
Into the Lab3 program,
insert the filename input.txt in the statement below:
myFileScanner = new Scanner (new File
( ) );
2.
Where will it assume the
file is?
|
3.
Now compile the program.
Did you get any compile errors?
What error did you get? Why?
|
4.
Correct the error by
adding an appropriate throws clause..
5.
Run the program. Since there is no file named input.txt, what
error message occurs?
|
6.
Insert an appropriate try catch block to catch the exception,
print an appropriate message and exit the program if the exception is thrown.
7.
Create a file on the C drive in the Temp directory named,
input.txt (it does not matter what is in the file)
8.
Alter the initialization of myFileScanner so that it contains
the absolute (complete) pathname to the file you just created. (Recall that an absolute path name begins
with the drive letter.) Write the path
name that you used in the block below.
|
9.
Hard-coding a filename into a program is evil. Alter your
program so that it gets the correct filename from the user, using the keyboard
scanner already in the Lab4 program.
10.
Check that your program works when you give it the correct
filename
11.
Now type in an incorrect filename. What error message is output
by your try/catch block?
|
12.
Alter your try catch block so that instead of quitting, your
program tries again until the desired filename is entered.
1.
This part of the lab asks you to actually process the data in
the following way. Note that may only
read the file data once.
2.
You are to:
a. Find and display
(with appropriate label), the smallest int in the file.
b. Determine whether
the value 13 is in the file and print a message telling how many times it
occurs.
3.
Create your own test file consisting of a series of ints and
test your program. Your file should be
named <yourfirstname>.txt
4.
Now copy the file numbers.txt to your working directory.
5.
The file was supposed to contain only ints but professors Harris
and Adams were tired when they created it so it has some junk in it. You must deal with the file as it
exists. Any bad data should be
ignored. Alter your program to
accommodate the bad data.
6.
Now run another test with the file numbers2.txt and insure that
it works properly.
DELIVERABLES