I'm working on an assignment for school, and am trying something beyond for extra credit. The program is to demonstrate the efficiency differences between a linear & binary search for a given array size of integers. I have a loop set up that creates an int[size] array, searches for a random number, then creates a new array of int[size\*2].

The results are then written to a text file. The output writes fine, but after compiling & running the program several times, the output file has that many sections of data.

This is my code that is nested inside a try/catch block:

```
File output= new File("c:\\BigOhResults.txt");
int counter=2;

if (output.canWrite() && output.exists()) {
    BufferedWriter out= new BufferedWriter(new FileWriter(output, true));
    out.write(type+" \n\n"); //writes the search type
    out.write(type+"Search Results\n\n");

    while (counter <= data.size()) {
        out.write(data.get(counter-1)+" millisecond runtime " +
        "for a "+ data.get(counter-2)+" random number " +"sample size\n");
        counter=counter+2;
    }
}

```

Is there any way I can erase the text within that output file upon each time the program is run?

the reason I'm doing this is the professor requires the result printout with the data graphed. I have already completed the graphing requirement, and it works fine. I just want to have the file printout match the graph printout.