#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char *argv[])
{
int fd = open(argv[1],O_RDONLY);
if(fd==-1)
{
perror("fd\n");
return -1;
}
char arr[20]={0};
read(fd,arr,20);
close(fd);
int fd2 = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0777);
if(fd2==-1)
{
perror("fd2\n");
return -1;
}
write(fd2,arr,20);
close(fd2);
return 0;
}
用read和write拷贝文件
最新推荐文章于 2024-07-16 22:46:11 发布