一、Linux系统下,一些关于文件操作的API
1.打开文件 open函数
2.读写文件 read/write函数
3.光标定位 lseek函数
4.关闭文件 close函数
二、打开/创建文件
open函数,使用open函数要包含一下三个头文件:
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
open函数一共有三种声明:
int open(const char *pathname,int flags);
int open(const char *pathname,int flags,mode_t mode);
int creat(const char* pathname,mode_t mode);
函数成功返回文件描述符,失败返回-1。
参数说明:
<1>.pathname:要打开的文件名(含路径,缺省路径时为当前路径)
<2>.flags:
- O_RDONLY 只读打开
- O_WRONLY 只写打开
- O_RDWR 可读可写打开