Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何删除 .txt 文件的内容以使其成为空白文件或完全删除该文件?我正在从 .txt 文件中读取,如果我不删除上次运行的内容,它将忽略我想要考虑的结果。
假设您的文件名为to_be_deleted.txt,您可以简单地使用以下命令将文件完全删除:
to_be_deleted.txt
delete 'to_be_deleted.txt';
另一方面,如果您只是想清除它的内容,只需使用fopenwrite 属性打开它,如下所示:
fopen
fopen('to_be_deleted.txt','w');