how would i go about adding an entry number at the start of a saved line of text to a .txt file. eg.
- 01, entry one
- 02, entry two
- 03, entry three
and so on
here is my code to write to the file
public void onClick(View v) {try {
BufferedWriter out = new BufferedWriter(new FileWriter("/sdcard/input_data.txt", true));
out.write(txtData.getText() + "," + dateFormat.format(new Date()));
out.close();
Have a counter field in your object, write its value each time an entry is written, and then increment it:
You should always close the writer in a finally block, to make sure it’s closed even if some exception is thrown.