今天给大家分享一下在linux应用层是如何进行文件操作的。
目的:
建立eepw.txt,通过写,读文件内容,实现文件的操作。
步骤:
1、宿主机建立文件
#include #include #include #include #include #include #define LENGTH 100 int main() { int file,len; char str[LENGTH]; file=open("eepw.txt",O_CREAT|O_RDWR,S_IRUSR|S_IWUSR); if(file) { write(file,"Hello,EEPW!\nHello,SINLINX!\n",strlen("Hello,EEPW!\nHello,SINLINX!\n")); close(file); } file=open("eepw.txt",O_RDWR); len=read(file,str,LENGTH); str[len]='\0'; printf("%s\n",str); }
2、交叉编译

3、将file文件拷贝到sin210开发板上

4、运行file文件

从结果上看,实现了预期的目标。
5、查看是否建立eepw.txt文件

发现系统文件中已经建立了预期的文件
6、查看建立文件内容

内容也是与程序中一致。
此次介绍到此为止!谢谢观看