[Plain Text] 纯文本查看 复制代码
DWORD WINAPI SetFilePointer(
__in HANDLE hFile,
__in LONG lDistanceToMove,
__inout_opt PLONG lpDistanceToMoveHigh,
__in DWORD dwMoveMethod
);
[C++] 纯文本查看 复制代码
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
_tsetlocale(LC_CTYPE, _T(""));
HANDLE hFile;
CHAR buffer[256] = {};
DWORD nByte;
hFile = CreateFile(_T("a.txt"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ReadFile(hFile, buffer, 256, &nByte, NULL);
buffer[nByte] = '\0';
_ftprintf(stdout, _T("a.txt 中的原始字符串: %S"), buffer);
SetFilePointer(hFile, 6, NULL, FILE_BEGIN);
ReadFile(hFile, buffer, 7, &nByte, NULL);
buffer[nByte] = '\0';
_ftprintf(stdout, _T("\n从开头偏移 6 个字符调整后读:%S"), buffer);
SetFilePointer(hFile, 8, NULL, FILE_CURRENT);
ReadFile(hFile, buffer, 7, &nByte, NULL);
buffer[nByte] = '\0';
_ftprintf(stdout, _T("\n\n从当前位置偏移 8 个字符调整后读:%S"), buffer);
_ftprintf(stdout, _T("\n\n文件总大小为:%d\n"), SetFilePointer(hFile, 0, NULL, FILE_END)); //从文件末尾移动 0 个字节以得到文件的长度
CloseHandle(hFile);
return 0;
}