一. 二进制文件读写
读的函数 fread()
fread的API
写的函数 fwrite()
fwrite的API
int main(){
char *read_path = "E:\\C_NDK_data\\LogViewPro.exe";
char *write_path = "E:\\C_NDK_data\\LogViewPro_write.exe";
//读二进制文件
FILE * read_fp = fopen(read_path, "rb");//rb读二进制的
//写二进制文件
FILE * write_fp = fopen(write_path,"wb");
char buff[50];
int len = 0;
while ((len = fread(buff,sizeof(char),50,read_fp)) != 0){
fwrite(buff,sizeof(char),len,write_fp);
}
fclose(read_fp);
fclose(write_fp);
system("pause");
return 0;
}
二. 获取文件大小
fseek() 设置流的文件位置为给定的偏移量:
fseek的API
ftell() 返回给定流 stream 的当前文件位置
ftell的API
int main(){
char *read_path = "E:\\C_NDK_data\\LogViewPro.exe";
FILE * read_fp = fopen(read_path, "r");
if (read_fp == NULL){
return 0;
}
fseek(read_fp,0,SEEK_END);//从文件的末尾做0个偏移
long fileSize = ftell(read_fp);
printf("%ld \n", fileSize);
fclose(read_fp);
system("pause");
return 0;
}