如何在 C# 中现有文本文件的顶部追加行
你能在这里帮我吗... 我想通过应用程序(c#-.Net2005)创建一个文本文件,并且需要为每个成功的事务更新它...我创建了文本文件并且更新也成功,但新行被添加为最后一行...但是我希望新添加的行应该是文本文件中的最顶层行...您能告诉我如何在 c# 中执行此操作吗?
Can you please help me here...
I wants to create a text file through application (c#-.Net2005)and need to update it for every sucessful transaction...I created text file and also updation is sucessful but new line is gets added as last line...BUT I want newly added line should be a TOPMOST line in the text file...Can you please tell me how can I do this in c#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它是在线更新的,并且只有一行在文件开头留有空间,并使用以下命令写入此位置。
如果您想保留某种日志文件,请将该行写入一个新文件并附加其余部分其他文件。这是非常昂贵的(性能方面)。除非您有充分的理由,否则您很可能不想这样做。
没有可接受的方法来写入最顶层条目是最新条目的日志文件。
马里奥
If it is on line you update and only one line leave space at the beginning of the file and write to this position using
If you want to keep some kind of a log file, write the line to a new file and appen the rest of the other file. This is very expensive (performancewise). Unless you have very good reasons, you most probably do not want to do this.
There is no acceptable way to write a log-file where the top-most entry ist the most recent one.
hth
Mario
我个人认为这个要求值得质疑。
Personally I think this requirement should be questioned.