然后在挂载操作成功之后进行打开->写入->关闭一个完整的操作:
/* 打开文件(若文件不存在则创建) */
fr = f_open(&fd, filename, FA_CREATE_ALWAYS | FA_WRITE);
if(fr == FR_OK)
{
printf("open file \"%s\" ok! \r\n", filename);
}
else
{
printf("open file \"%s\" error : %d\r\n", filename, fr);
}
/* 向打开的文件中写入内容 */
fr = f_write(&fd, write_dat, sizeof(write_dat), (void *)&write_num);
if(fr == FR_OK)
{
printf("write %d dat to file \"%s\" ok,dat is \"%s\".\r\n", write_num, filename, write_dat);
}
else
{
printf("write dat to file \"%s\" error,error code is:%d\r\n", filename, fr);
}
/* 操作完成,关闭文件 */
fr = f_close(&fd);
if(fr == FR_OK)
{
printf("close file \"%s\" ok!\r\n", filename);
}
else
{
printf("close file \"%s\" error, error code is:%d.\r\n", filename, fr);
}
|