0

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?

DrXCheng
  • 3,992
  • 11
  • 49
  • 72
  • Sample code is nice...Like what you've tried. Most people won't help unless you show effort in code. – Jon Egeland Jan 19 '12 at 19:41
  • Unless you have a _lot_ of work "todo", processing the file should be nearly instant. – cdeszaq Jan 19 '12 at 19:41
  • Duplicate: check out this question and answer I flagged it to: http://stackoverflow.com/questions/822150/modify-a-txt-file-in-java – Michael Dillon Jan 19 '12 at 19:42
  • @MichaelDillon I believe OP question was not about how to modify file, but about how to achieve reliable behavior of program in presence of possible crash. – Victor Sorokin Jan 19 '12 at 19:44
  • Let me see if I understand your question: You have a long process that you want to be able to stop and then resume later from the last unprocessed item. Am I correct? – TeaOverflow Jan 19 '12 at 19:47
  • @MichaelDillon I have checked that post, but that is not what I want. – DrXCheng Jan 19 '12 at 20:19

2 Answers2

4

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
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Victor Sorokin
  • 11,878
  • 2
  • 35
  • 51
0

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.

Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79