@(C语言)
[toc]
读文件
//读文件
int main(){
char * path ="";
//打开路径
FILE *fp =fopen(path, "r");
char buff[50];
while (fgets(buff, 50, fp)) {
printf("%s",buff);
}
fclose(fp);
return 0;
}
写文件
//写文件
int main(){
char * path ="";
FILE *fp =fopen(path, "w");
if (fp==NULL) {
printf("failed ....")
}
char *text ="test write file";
fputs(text, fp);
fclose(fp);
return 0;
}
读写二进制文件
int main() {
char * read_path = "G:\\0_preClass\\NDK\\class\\Ls_C5\\files\\LogViewPro.exe";
char * write_path = "G:\\0_preClass\\NDK\\class\\Ls_C5\\files\\LogViewPro_write.exe";
//read
FILE * read_fp = fopen(read_path, "rb");
//write
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;
}