Reputation: 4132
I have a todo
file listing all the item to process, I want my program to read the todo
list and process each item.
There is no problem if it can be done in once. But there is possibility that I need to manually stop/kill the program. And next time I run the program again, it will process the remaining item. So reading in all item and output the remaining does not work. One solution is to output all the processed item, and next time I can read all item and all processed item to get a new todo
list.
Is there a way to modify the current todo
file? Or is there any other solution to achieve this?
Upvotes: 0
Views: 480
Reputation: 11996
Usually, you have todo
file (some Java EE people call it journal) like this:
TODO item1
TODO item2
TODO item3
...
During execution of your program, as it processes each item, it must append "done" marks to that journal, so it will look like:
TODO item1
TODO item2
TODO item3
DONE item1
DONE item3
...
Next time when you start your program, it will read journal, remove all items marked as "done" and will pass rest of the items to processing module, so after restart but before start of processing file will look like this:
TODO item2
Upvotes: 4
Reputation: 16060
Read the file line by line, store the linenumber along with the MD5 of prozessed part of the file. If you restart, read everything until the line, Check if the file has changed. And begin with the next line.
Upvotes: 0