1. _read() + _write() + _lseeki64()
①. char lpBuf[4] = "";
int fd; //句柄
int readlength = 0;//讀取到的長度
int nbytes = 4;//nbytes是想要讀取的長度(爲4字節)
readlength = _read(fd, lpBuf, nbytes);//讀取fd指向的文件,讀取4字節到lpBuf中
②.string data;
int len;
_write(fd,data.c_str(), len);//將字節長度爲len內容爲data的信息寫進fd句柄指向的文件中
③. _lseeki64(fd, pos, SEEK_SET);//從文件開頭移動pos位置,並返回在64位整數的偏移量
2. read
#include <unistd.h>
ssize_t read(int fd, void *buf, size_t nbytes);
返回值: 讀取到的字節數; 0(讀到 EOF); -1(出錯).
注意: read 函數從 fd 指定的已打開文件中讀取 nbytes 字節到 buf 中.
3. write
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t nbytes);
返回值: 寫入文件的字節數(成功); -1(出錯).
注意: write 函數向 fd 中寫入 nbytes 字節數據, 數據來源爲 buf . 返回值一般總是等於 nbytes, 否則就是出錯了. 常見出錯原因是磁盤空間滿了或者超過了文件大小限制.