I want to save two strings to one text file at the same time. One of the strings constantly inputs data, while the other only writes data when a button is clicked. However, when I click the button to add the value from there to the txt file, it writes, but it deletes all data from the other string before it. After, the other string goes back to writing as normal.
Here is the code for the two strings printing to the file:
public void onClick(View view) {
try {
EditText bodyText;
bodyText = (EditText) findViewById(R.id.ETName);
String name = bodyText.getText().toString();
PrintWriter out = new PrintWriter(new BufferedWriter(
new FileWriter("/sdcard/Accelerometer.html")));
out.println("<h3 style=padding-left:20px;>" + name
+ "</h3><br>");
// new arraylist
out.close();
} catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage());
e.printStackTrace();
}
}
});
try {
PrintWriter writer = new PrintWriter(new BufferedWriter(
new FileWriter("/sdcard/Accelerometer.html", true)));
writer.println("<h3 style=padding-left:20px;>" + text
+ "</h3><br>");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Any help would be great, thanks.