3.1.1、应用编程框架介绍
3.1.1.1、什么是应用编程
3.1.1.2、什么是文件IO
3.1.2.文件操作的主要接口API
3.1.2.1、什么是操作系统API
3.1.2.2、linux常用文件IO接口
3.1.2.3、文件操作的一般步骤
静态文件:存在块设备中尚未被打开的文件。
动态文件:文件被打开后按照特定方式存放在内存中的文件。
3.1.2.4、重要概念:文件描述符fd
3.1.3.一个简单的文件读写实例
3.1.3.1、打开文件与关闭文件
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main( int argc, char *argv[] )
{
int ret = -1;
int fd = -1;
//1.打开文件
fd = open( "a.txt", O_RDWR );
if( fd == -1 )
{
perror( "open failed" );
exit(1);
}
printf( "文件描述符:%d\n", fd );
printf( "a.txt文件打开成功\n" );
//2.关闭文件
ret = close( fd );
if( ret == -1 )
{
perror( "close failed" );
exit(1);
}
return 0;
}