Android - Remove the last incomplete line in .txt file
<p>The app records the sensor data and write the data into a .txt file into the phone SD card.</p>

<p>During the data collection process, one may press the stop button anytime to stop writing.</p>

<p>The relevant writing part is as follows:</p>

<pre><code>    myFile = new File("/sdcard/ResearchData/"
                            + txtData.getText() + ".txt");
                    myFile.createNewFile();

                    fOut = new FileOutputStream(myFile);
                    myOutWriter = new OutputStreamWriter(fOut);
                    myBufferedWriter = new BufferedWriter(myOutWriter);
                    myPrintWriter = new PrintWriter(myBufferedWriter);

myPrintWriter.write(currentTime - startTime + " " + acceleration[0]
                    + " " + acceleration[1] + " " + acceleration[2] + "\n");
</code></pre>

<p>Once the STOP button is pressed, the following codes are executed.</p>

<pre><code>myOutWriter.close();
fOut.close();
</code></pre>

<p>The codes are functioning okay, but the only problem is that because one may press STOP anytime, so the last line of the .txt file is always INCOMPLETE. Due to the need for data analysis, I need the data to be a nice rectangular matrix. Thus, <strong>I need to remove the last incomplete line. How may I do it?</strong></p>

<p>Or solve this question from another angle. Can I make the STOP button synchronous to the writing process? i.e., after one line has been completely written in, then the STOP is checked.</p>
