Java FileWriter help

Question!

Okay... so I have a fairly interesting error... I declare a FileWriter called file, and I have it go through the following for loops:

for (int i = 0; i < a.radtot; i++) {
    file.write("" + i * a.rstep);

    for (int n = 0; n < a.timetot; n++) {
        file.write("\t " + T[n][i]);
        System.out.println(T[n][i] + " " + n + " " + i);
    }

    file.write("\n");
}

At the end of it, the System.out.println command prints what I expect it to, but the file cuts off midway... As in, instead of printing out everything System.out does... it stops in the middle. Does anyone happen to know why it would do that? Am I doing something wrong?



Answers

Try adding:

file.close();

The close() method description says:

Closes the stream, flushing it first.



This video can help you solving your question :)
By: admin