In my program I need to update the Balance column of the text file each time the user does a withdrawal. I used both the write methods as well as the append methods, but to no a
Consider a file to be a piece of paper with something written on it. At the end of the writing there is still white paper left, so you can append anything you want. If you want to change something in the middle, you can erase some text and write something else. However, you can only replace text with as many letters as you erased. You can not erase 4 letters and write 6 letters, there is simply no space. Therefore, if the balance increases from 900 to 1100, there is no space left in the file. There is one extra letter, which can not be stored unless the remaining part of the file is rewritten.
Sometimes if you want to change something on a piece of paper, it is easier to get a blank piece of paper and copy the original, including the changes you had in mind. This is also often done when a file is changed. Instead of writing just the changes, the changed file is prepared in memory and written over the original file.
The only simple way to do this is to rewrite the entire contents of the text file every time you make any change. But this is awful for several reasons:
You can use fixed width columns to allow seeking and writing into your file without having to rewrite the entire file, but there are still problems:
I'd suggest that you use a database instead. There are databases that you can install locally and require no administation (SQLite for example).