c实现功能(12)利用stat函数对大文件进行拷贝

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(){
    struct stat st = {0};
    //利用stat结构体对文件的相关信息进行保存
    stat("D:\\test\\a.wmv", &st);
    //在堆中分配文件大小的内存
    char *array = malloc(st.st_size);

    //读取文件
    FILE *p = fopen("D:\\test\\a.txt", "rb");
    //拷贝文件
    fread(array, sizeof (char), st.st_size, p);

    fclose(p);

    //打开需要写入的文件
    p = fopen("D:\\test\\b.wmv", "wb");
    //写入内存中拷贝的信息
    fwrite(array, sizeof (char), st.st_size, p);

    fclose(p);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/hc1151310108/article/details/82953182