1、stat()函数
#include <sys/stat.h>
int stat( const char * path,
struct stat * buf );
path
The path of the file or directory that you want information about.
buf
A pointer to a buffer where the function can store the information; see below.
size_t filesize(const char* file_name)
{
size_t filesize = _maxFileSize+1;
if (file_name != NULL)
{
struct stat statbuff;
if(stat(file_name, &statbuff) == 0)
{
filesize = statbuff.st_size;
}
}
return filesize;
}
2、fstat()函数

本文介绍了两种获取文件大小的方法:使用stat()和fstat()函数。通过示例代码展示了如何利用这些函数来获取指定文件的大小。

1188

被折叠的 条评论
为什么被折叠?



