获取文件大小:
int getFileLength(const char* fileName)
{
int length = 0;
FILE *file;
file = fopen(fileName, "r");
if (file == NULL)
{
return -1;
}
fseek(file, 0L, SEEK_END);
length = ftell(file);
fclose(file);
return length;
}
已知文件大小读文件:
int getFileData(const char* fileName, unsigned char *data, int length)
{
FILE *file;
file = fopen(fileName, "r");
if (file == NULL)
{
return -1;
}
int ret = fread(data, 1, length, file);
fclose(file);
return 0;
}
已知文件大小写文件:
int writeFile(const char* fileName, unsigned char *data, int size)
{
FILE *file;
file = fopen(fileName, "wb");
if (file == NULL)
{
return -1;
}
int ret = fwrite(data, 1, size, file);
fclose(file);
return 0;
}