//盗墓者是个丑奴儿,原
//博主个人网站 :https://daomu.kaige123.com
//打完一波小广告,进入正题
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
//open打开文件,lseek向后偏移字节,偏移后read在读取。
//SEEK_SET从头向后偏移
//O_RDWR以已可读可写方式打开文件
int main(void){
int i=open("stu.java",O_RDWR);
char buf[100]={0};
int ffd=lseek(i,3,SEEK_SET);
read(i,buf,100);
printf("%s \n",buf);
close(i);
return 0;
}
运行结果:
偏移3字节后,读取:
原文件内容: