[Solved] Calculating sum of numbers from a file?


The answer to your problem with writing to the file is every time you are writing to the file you are over writing what was there before, what you need to do is change

FileOutputStream fos = openFileOutput("TotalSavings", Context.MODE_PRIVATE)

to:

FileOutputStream fos = openFileOutput("TotalSavings", Context.MODE_PRIVATE | Context.MODE_APPEND)

This tells android you want to append to the file as well as keep it private.

EDIT
You new issue is because you are placing the text directly after the other text, you want to force a new line into your file. The simplest way will be something like:

String totalFromField = total.getText().toString() + "\n";
fos.write(totalFromField.getBytes());

1

solved Calculating sum of numbers from a file?