???如何把文件剪短,来帮忙呀。

jiangwentao 2003-01-13 11:00:32
我的程序有如下运行情况,本来是个大文件,可后来文件的后面大部分都不需要了,只要前面的部分,怎么才能直接把文件剪短呢。我现在的方式是重新开一个新文件,把现在的一部分考过去,把原来的删除,把现在的改名为原来的。
...全文
38 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
panxiongfei 2003-02-23
  • 打赏
  • 举报
回复
df
atma 2003-01-16
  • 打赏
  • 举报
回复
好像说的不清楚.你要减短的是你的程序源文件还是其他的文件?
cache2002 2003-01-16
  • 打赏
  • 举报
回复
删掉后面的不行吗,你说清楚一点,
qianxh 2003-01-16
  • 打赏
  • 举报
回复
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.

BOOL SetEndOfFile(

HANDLE hFile // handle of file whose EOF is to be set
);


Parameters

hFile

Identifies the file to have its EOF position moved. The file handle must have been created with GENERIC_WRITE access to the file.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old EOF position and the new position are not defined.
If you called CreateFileMapping to create a file-mapping object for hFile, you must first call UnmapViewOfFile to unmap all views and call
CloseHandle to close the file-mapping object before you can call SetEndOfFile.
ToUpdate 2003-01-14
  • 打赏
  • 举报
回复
up
killjoy 2003-01-13
  • 打赏
  • 举报
回复
我建议你先开个缓冲区,把文件读入,然后对文件进行操作(其实就是对内存中的那部分数据)然后把文件写入。在对缓冲区操作的时候,文件是关闭的。
不知道你要保留的数据位于文件什么位置。如果你的程序对效率要求很高建议不要用malloc,而是直接用数组。因为这样速度快。

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧