清除文本文件的内容 [英] Clear contents of a Text File

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

问题描述

我正在开发服务器/客户端应用程序。我想在名为Information.txt的文本文件中维护所有活动客户端的信息。我每3个seonds后更新这个文本文件。所以,我希望文本文件在每3秒后清除所有内容而不删除文件。有什么办法吗? :(我不想使用freopen()。

I am working on a sever/client applicataion. I want to maintain information of all active clients in a text file named "Information.txt". I update this text file after every 3 seonds. So, I want the text file to clear all of its contents after every 3 seconds without deleting the file. Is there any way to do it ? :( I don''t want to use freopen().

推荐答案

不要打扰,只需使用 seek 将文件指针返回到文件的开始,然后写一个 EOF 如果你愿意的话。

在Win32上有''一个API,用于设置文件的范围,您可以使用该文件来防止任何读取过EOF的内容,即使它选择了。如果您的代码完全控制了文件,那么这是不必要的。
Don''t bother, just use seek to return the file pointer to the beggining of the file and then write an EOF if you want to.
On Win32 there''s an API to set the extent of the file which you could use to prevent anything reading past that EOF even if it chose to. That''s not necessary though if your code is in full control of the file.


用流阅读器打开文件然后什么都不写

喜欢: -



Const ForWriting = 2



设置objFSO = CreateObject(Scripting.FileSystemObject)

设置objFile = objFSO.OpenTextFile(C:\Scripts\Test.txt ,ForWriting)



objFile.Write

objFile.Close
open the file with stream reader then write nothing
like:-

Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForWriting)

objFile.Write ""
objFile.Close


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

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