怎么获取一个文件的大小
java中的file.length()如果用C来写的话,应该怎么写啊。。。
[解决办法]
stat
[解决办法]
#include <sys/stat.h>struct stat buf;if(stat("filename", &buf) == -1){ perror("fail to stat"); continue;} else { printf("the size: %d\n", buf.st_size);}
[解决办法]
这个是平台相关的。Windows下用GetFileSizeEx()。
[解决办法]
struct stat getfilestat(char filename[NAMELEN]) { struct stat fstat; if(stat(filename, &fstat) == -1) { perror("get file stat"); return; } return fstat; }
[解决办法]
用boost::filesystem库
非常easy:
path curpath(sFile);
return file_size(curpath);
[解决办法]
C语言快速获取文件的大小的两种方法:
1、
int size;
FILE *fp;
fp=fopen("file","rb");
fseek(fp,0,SEEK_END);
size=ftell(fp);
flcose(fp);
2、在linux下
#include <sys/stat.h>int file;struct stat statBuf;file = open("filename",O_RDONLY);if(file < 0) printf("file open err");if(fstat(file,&statBuf)<0) printf("fstat err");else printf("file size is %d\n",statBuf.st_size);
[解决办法]
你不用 Linux 的吗!man 打开手册页命令啊!有问题找男人!
[解决办法]
int size;
FILE *fp;
fp=fopen("file","rb");
fseek(fp,0,SEEK_END);
size=ftell(fp);
flcose(fp);