writing to a file, but not just at the end
<p>I want to write something to a file line by line.
I have the problem, that this process takes a lot of time and get canceld sometimes. The current version write the stuff to the file just at the end. Is it possible to write it to the file line by line?</p>

<p>E.g. if I abboard after line 4 (of 400) the file currently is empty. But I want to have the 4 line already in the file.</p>

<p>Here is my code:</p>

<pre><code>String path = args[0];
String filename = args[1];

BufferedReader bufRdr = // this does not matter

BufferedWriter out = null;
FileWriter fstream;
try {
    fstream = new FileWriter(path + "Temp_" + filename);
    out = new BufferedWriter(fstream);
} catch (IOException e) {
    System.out.println(e.toString());
}

String line = null;

try {
    while ((line = bufRdr.readLine()) != null) {            
        // HERE I'm doing the writing with out.write
        out.write(...);
    }
} catch (IOException e) {
    System.out.println(e.toString());
}

try {
    out.close();
} catch (IOException e) {
    System.out.println(e.toString());
}
</code></pre>
