C 语言获取文件流大小

1. open

    int file_size(char* filename)  
    {  
        FILE *fp=fopen(filename,"r");  
        if(!fp) return -1;  
        fseek(fp,0L,SEEK_END);  
        int size=ftell(fp);  
        fclose(fp);  
          
        return size;  
    }  

2. stat

int file_size2(char* filename)  
{  
    struct stat statbuf;  
    stat(filename,&statbuf);  
    int size=statbuf.st_size;  
  
    return size;  
}  

3. struct stat 操作 小结

https://blog.csdn.net/wh_19910525/article/details/13503221

你可能感兴趣的:(C 语言获取文件流大小)