File I/O Assignment

See this link for Assignment Policies, Submission Instructions, and Grading Guidelines.

Instructions

1.      Write a Java application that does the following:

2.      Instantiate an array of Strings that will store up to one million elements.

3.      Read each word from the input file.

4.      Store each word in the array.

5.      Display the index and each word in the array BACKWARDS on the computer screen.

6.      Also, store the same information in the output file.

7.      For example, if the input file has the text:
This is a pen.
Mikka bouzu.
Hello, World!
Then the output to the screen should be:
index          word
7                World!
6                Hello,
5                bouzu.
4                Mikka
3                pen.
2                a
1                is
0                This
And the output file should also have the text:
index          word
7                World!
6                Hello,
5                bouzu.
4                Mikka
3                pen.
2                a
1                is
0                This

8.      Use 1st command-line argument as the name of the input file.

9.      Use the 2nd command-line argument as the name of the output file.

10.  See the slides on more details about command-line arguments. Basically, you need to click “Build”, then “Run Arguments”. A text box will appear at the top of jGRASP. Type the name of your input file, then type the name of your output file.  The name of your input file is stored within “args[0]”. The name of your output file is stored within “args[1]”.

11.  For displaying errors and giving feedback, use either the System or JOptionPane classes. Specifically, if the user does not enter enough command-line arguments, display a message. If the file cannot be found, display a message. If the program is finished, display a message.

1.      To read from an input file, see the example ReadFromFile.java

2.      Use the File and the Scanner class to create a connection to the input file.

3.      Using a while loop & the Scanner method “hasNextLine()”, loop through each line of the input file and read each word from the input file into an array of Strings by using “next()

4.      When you write to screen & the output file, loop through the array of Strings backwards. Each array element in the array of Strings will be one line in the output file.

5.      To write to an output file, see the example WriteToFile.java

6.      Don’t forget to use try-catch blocks, so that your program cannot crash.

7.      WARNING: DO NOT try to write the whole program at once. Make sure the most basic part works first. Then, gradually add to it until your program is complete. Writing methods will help you organize your code as well.

 

 

 

© 2007 William Albritton