简体   繁体   English

修改Java中的文本文件

[英]Modify text file in Java

I have a todo file listing all the item to process, I want my program to read the todo list and process each item. 我有一个todo文件,列出了所有要处理的项目,我希望程序读取todo列表并处理每个项目。

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. 一种解决方案是输出所有已处理的项目,下次我可以读取所有项目和所有已处理的项目以获取新的todo清单。

Is there a way to modify the current todo file? 有没有办法修改当前的todo文件? Or is there any other solution to achieve this? 还是有其他解决方案来实现这一目标?

Usually, you have todo file (some Java EE people call it journal) like this: 通常,您具有如下所示的todo文件(某些Java EE人们称其为日记):

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

Read the file line by line, store the linenumber along with the MD5 of prozessed part of the file. 逐行读取文件,将行号与文件的被压缩部分的MD5一起存储。 If you restart, read everything until the line, Check if the file has changed. 如果重新启动,请阅读所有内容,直到该行检查文件是否已更改。 And begin with the next line. 并从下一行开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM