截断该文件 [英] Truncate file

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

问题描述

我使用的fopen位置fseeko64 ftello64​​ FCLOSE等对文件操作。

I am using fopen fseeko64 ftello64 fclose etc. to operating on a file.

我怎样才能截断一个文件?我知道,有在C.所有我想做这个没有标准的方式是某种方式,可以在任何Win32平台工作。我使用MinGW的GCC编译器。

How can I truncate a file? I know that there is no standard way to do this in C. All I want is some way that will work on any win32 platform. I'm using mingw gcc to compile.

请注意:我的意思是截断该文件的大小,以指定的大小,不使其0尺寸。而使用类似副本一部分绝招到另一个文件,并删除/重命名是不恰当的。

Please note: I meant truncate the size of the file to a specified size, not make it 0 size. And using a trick like copy part to another file and delete/rename is not appropriate.

推荐答案

SetEndOfFile ()

得到一个处理与写访问文件,设置文件指针,然后调用SetEndOfFile()。

Get a handle to the file with write access, set the file pointer, then call SetEndOfFile().

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

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