文件复制

来源:互联网 发布:比尔盖茨 关于编程 编辑:程序博客网 时间:2024/06/08 15:57

int main()
{
 int fd1 = open("1.pptx",O_RDONLY);
 if(fd1 == -1)
 {
  perror("open fd1");
  return -1;
 }
 int fd2 = open("2.pptx",O_WRONLY|O_CREAT,0777);
 if(fd2 == -1)
 {
  perror("open fd2");
  return -1;
 }
 int ret=0;
 char buf[SIZE] = {0};
 while(ret = read(fd1,buf,SIZE))
 {
        if(ret==-1)
  {
   perror("read");
   break;
  }
  write(fd2, buf, ret);
 }
    printf("复制完成\n");
    close (fd1);
    close (fd2);
    return 0;
}
原创粉丝点击