"抗追加"文本文件? [英] "Anti-append" of text files?

查看:79
本文介绍了"抗追加"文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要阅读一个文本文件,每行只执行一次。每排需要一分钟左右。我有很多行。为了举个例子,让我们保持这个简单。首先,不,我不能一次完成,过程太长。

I need to read a text-file and act exactly once per row. It takes a minute or so per row. I have a lot of rows. For the sake of example, let's keep this simple. First of all, no, I can't do that all at once, too long process.

所以我有一个文本文件,其行如下:

So I have a text file with rows like this:

1

2

3

4

5

明天会有结束

6

7

假设我现在可以运行程序足够长时间来处理1和2.所以我想从3继续。所以在今天之后文件需要看起来像

Let's say I'm able to run the program now long enough to handle 1 and 2. So I want to continue from 3. So after today the file needs to look like

3

4

5

因为我明天加了一些,看起来像

and since I add some tomorrow, it looks like

3

4

5

6

7

如何保持此类文件滚动?这基本上类似于"反附加"。即append所说的"添加一行文字以结束"现在需要从头开始删除一行文本。

How do I keep this kind of file rolling? This is basically like "anti-append" i.e. where append says "add a row of text to end" this requires now to remove a row of text from the beginning.

我一次只处理一行,总是第一行。

I'm handling exactly one row at a time and always the first row.

哦,关闭文件介于两者之间是可能的。每行的实际读数是每毫秒毫秒,并且可以在每次操作后关闭。进入下一行只需要一段时间。

Oh and closing the file in-between is possible. The actual reading of each line is milliseconds per time and can be closed after each operation. It just takes time to progress to the next line.

我可以在每个处理行的末尾打印"ididthisonealreadysoskipit"。所以没关系,删除行不是100%needeed,我只需要一种方法从上次执行继续。

I could print at the end of each handled line "ididthisonealreadysoskipit" so that's ok, the deleting of lines is not 100% needeed, I just need to have a way to continue from the last execution.

推荐答案

只有这样你才能从文本文件的开头删除行是重写整个文件。换句话说,您可以将未读文本行复制到新文件,关闭并删除旧文件,然后重命名新文件。
The only way you can remove lines from the beginning of a text file is to rewrite the entire file. In other words, you could copy the unread text lines to a new file, close and delete the old file, and rename the new file.


这篇关于"抗追加"文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆