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?

6
  • Sample code is nice...Like what you've tried. Most people won't help unless you show effort in code. Commented Jan 19, 2012 at 19:41
  • Unless you have a lot of work "todo", processing the file should be nearly instant. Commented Jan 19, 2012 at 19:41
  • Duplicate: check out this question and answer I flagged it to: stackoverflow.com/questions/822150/modify-a-txt-file-in-java Commented Jan 19, 2012 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. Commented Jan 19, 2012 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? Commented Jan 19, 2012 at 19:47

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.