2021-08-02

Linux创建并写入文件

write函数头文件指令:man 2 write
close函数头文件指令:man 2 write
strlen函数头文件指令:man strlen
write(fd,buf,strlen(buf));
close(fd);

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main()
{
       int fd;
       char *buf = "chenlichen hen shuai!";
       fd = open("./file1",O_RDWR);
       if(fd == -1){
             printf("open file1 failed\n");
             fd = open("./file1 ",O_RDWR|O_CREAT,0600);
             if(fd > 0){
             printf("craet file1 success\n");


             }

       }
             printf("open success :fd = %d\n",fd);
             write(fd,buf,strlen(buf));
             close(fd);

       return 0;
}
                                                                                                                                        
                                                                                                                                            
上一篇:jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)


下一篇:云服务器windows server2019安装.net3.5环境(实战测试教程)