#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char* argv[])
{
//打开文件读取文件大小
{
FILE* fp = fopen("test.txt", "r");
fseek(fp, 0, SEEK_END);
int len = ftell(fp);
printf("file size:%d\n",len);
fclose(fp);
}
//用stat读取文件 节省开销
struct stat buf;
int ret = stat("test.txt",&buf);
printf("file size:%d\n",buf.st_size);
system("pause");
return EXIT_SUCCESS;
}
C语言-stat获取文件属性
最新推荐文章于 2024-08-04 14:29:09 发布