C 语言获取文件流大小

2018-04-13  本文已影响11人  that_is_this

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

上一篇下一篇

猜你喜欢

热点阅读