备注:
先建立要读写的文件。RDWR_test.txt,RDWR_test.txt.bak
代码:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/**********************************************
**********************************************/
int main(int argc, char* argv)
{
int fd_rsc = 0;
int fd_det = 0;
int len = 0;
char buf[500];
int wr_len;
fd_rsc = open("RDWR_test.txt",O_RDONLY);
printf("fd_rsc=%d\n",fd_rsc);
fd_det = open("RDWR_test.txt.bak",O_WRONLY|O_CREAT,0777);
printf("fd_det=%d\n",fd_det);
do
{
len = read(fd_rsc,buf,sizeof(buf));
printf("read file length is:%d\n",len);
wr_len = write(fd_det,buf,len);
printf("write file length is:%d\n",wr_len);
}while(0<len);
close(fd_rsc);
close(fd_det);
return(0);
}