How can I modify this Java program to read in the names from a file designated in the command line?
<p>Right now I have this program set up to where I can input names of boats in the command line i.e. C:\java Proj3 "Boat 1" "Boat 2" "Boat 3"
and it prints the results to the command line based on the specs.
Instead, I want to type something like this in the command line C:\java Proj3 "C:\class\Java\boatnames.txt" "C:\class\Java\results.txt"
so the args come from the file specified and the results are printed in a text file instead of on the screen. I changed the println's to printf's, but that's it so far. I deleted all my other failed attempts at this. I even tried creating another class called createfile.java that had private Formatter x; and some openFile, closeFile, and addRecords methods, but if I move the output over there and try to put it in addRecords, it doesn't know what the variable i is, and I'm guessing there must be a simpler way where I don't have to create that createfile class.</p>

<p>Here is my code(I didn't include the other classes since all I need to do is replace the args from the command line with args from a txt file in the command line):</p>

<pre><code>import java.util.*;
import java.io.*;
import java.lang.*;
import java.swing.*;

public class Proj3 {
    public static void main(String args[]) {

            Boat[] Boats;
        char   firstChar;
        char   secondChar;
        int    i;    

        Boats = new Boat[args.length];

        for (i = 0; i &lt; args.length; i++) {

            firstChar = args[i].toUpperCase().charAt(0);
            secondChar = args[i].toUpperCase().charAt(1);

            if ((firstChar == 'B') || (firstChar == 'C') || (firstChar ==     'N')) {
                Boats[i] = new SailBoat();
            } else {
                Boats[i] = new RaceBoat();
            }

            Boats[i].setName(args[i]);

            if ((secondChar == 'A') || (secondChar == 'E')) {
            Boats[i].goFast();
            } else {
                Boats[i].goSlow();
            }
        }


        for (i = 0; i &lt; args.length; i++) {
            System.out.printf("Boat number " + (i + 1) + " - \n");
            System.out.printf("   ");
            Boats[i].printBoat();
            System.out.printf("   ");
            Boats[i].whatIsBoatState();
        }




    }
}
</code></pre>
