#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(){
// 打开eng.txt文件
int srcfd = open("english.txt", O_RDONLY);
if (srcfd == -1)
{
perror("open");
return -1;
}
// 创建一个新的文件
int destfd = open("copy.txt", O_WRONLY | O_CREAT, 0664);
if(destfd == -1){
perror("open");
return -1;
}
// 频繁的读写操作
char buf[1024] = {0};
int len = 0;
while((len = read(srcfd, buf, sizeof(buf))) > 0){
printf("%d\n", len);
write(destfd, buf, len);
}
printf("%d\n",len);
// 关闭文件
close(srcfd);
close(destfd);
return 0;
}
linux拷贝一个文件的实现
最新推荐文章于 2023-11-08 16:54:50 发布