【问题标题】:Delete End of File删除文件结尾
【发布时间】:2010-10-24 02:21:06
【问题描述】:

例如,如果我在文件末尾调用 WriteFile,然后我想删除写入的字节,我该怎么做?我是否必须将文件的内容读入缓冲区,重新创建文件并写入所需的字节,还是有更简单的方法?

【问题讨论】:

    标签: c winapi


    【解决方案1】:

    Seek 到您要截断的文件位置(如果您不在那里),然后调用恰当命名的 SetEndOfFile() 函数。

    【讨论】:

      【解决方案2】:

      在兼容 Posix 的系统上(Unix、Linux 和其他系统(Windows 7 再次具有 Posix 层))

      int truncate(const char *path, off_t length); 
      int ftruncate(int fildes, off_t length);
      

      http://www.opengroup.org/onlinepubs/009695399/functions/truncate.html

      http://www.opengroup.org/onlinepubs/009695399/functions/ftruncate.html

      【讨论】:

        猜你喜欢
        • 2012-12-11
        • 2019-07-21
        • 2015-06-20
        • 1970-01-01
        • 1970-01-01
        • 2011-03-21
        • 2011-05-03
        • 2021-12-22
        • 2017-04-06
        相关资源
        最近更新 更多