打开文件及文件读写
更多...
打开文件及文件读写
源码
#include <rtthread.h>
#include <dfs_posix.h>
static void readwrite_sample(void)
{
int fd, size;
char s[] = "RT-Thread Programmer!", buffer[80];
fd =
open(
"/text.txt", O_WRONLY | O_CREAT);
if (fd >= 0)
{
}
fd =
open(
"/text.txt", O_RDONLY);
if (fd >= 0)
{
size =
read(fd, buffer,
sizeof(buffer));
rt_kprintf(
"Read from file test.txt : %s \n", buffer);
if (size < 0)
return ;
}
}