java print stream and printwriter
<p>I am stuck on why my program is not working, I am trying to print to a file however, where it says <code>student[i].listCourses(System.out);</code> I actually need it to print to the test.txt file also but I tried putting in outputFile and it didn't work</p>

<pre><code>   System.out.println("Please Enter A FileName");
  // Create a PrintWriter object and open the file.
  PrintWriter outputFile = new PrintWriter("test.txt");

  // Get data and write it to the file.
  // Continue reading till a blank line is entered
  int i=0;  
  do
  {

    while ((student[i] != null)&amp;&amp;(i &lt;= student.length)){
        student[i].addCourse(course[i]);
        outputFile.println(student[i].toString());
        student[i].listCourses(System.out);
        i++;
    }
</code></pre>

<p>and this is how listcourses is declared </p>

<pre><code>public void listCourses(PrintStream p) {
        for (Course crs: courses)
            if (crs != null)
                p.println(crs);
    }
</code></pre>
