打开文件和写文件的操作
来源:互联网 发布:守望先锋手机数据查询 编辑:程序博客网 时间:2024/05/18 02:32
使用系统调用的:open好write
代码:
//打开文件和写问件#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <sys/fcntl.h>#include <sys/types.h>#include <errno.h>const char* msg = "hello world \n";int main(){ close(1); //close(2); int fd = open("./log",O_CREAT|O_RDWR,0666); //int fd1 = open("./log1",O_CREAT|O_RDWR,0666); //int fd2 = open("./log2",O_CREAT|O_RDWR,0666); //int fd3 = open("./log3",O_CREAT|O_RDWR,0666); if(fd < 0 ) { exit(-1); } printf("%d\n",fd); int i = 10; //printf("%d\n",fd1); //printf("%d\n",fd2); //printf("%d\n",fd3); while(i) { i--; write(fd,msg,strlen(msg)); } close(fd); //close(fd1); //close(fd2); //close(fd3); return 0;}
运行结果:
分析:使用>log可以创建一个log文件,不使用的话这个程序是不会自动创建log文件的
0 0
- 打开文件和写文件的操作
- Linux系统文件的打开/读/写操作
- 文件的写操作
- 文件的操作1----打开关闭文件
- 目录的操作和Excel文件的链接与打开
- 文件操作 写文件
- 文件操作《11》学生成绩的保存和打开
- 13.2.2 打开文件、新建文件和关闭文件操作
- C++文件操作:打开文件和写入文件
- C++文件操作:打开文件和写入文件
- C++文件操作:打开文件和写入文件
- C++写一个打开文件的百宝箱
- linux内核空间 打开、读、写等文件操作实现
- Python open()函数文件打开、读、写操作详解
- Python open()函数文件打开、读、写操作 0602
- Go 文件操作(创建、打开、读、写)
- C语言简单的文件打开/读取数据/写回文件操作
- 文件的打开和关闭
- 基本的sql语句
- HTTP tunneling工具-端口转发
- ERROR C2514:XXX类没有构造函数
- Sublime text 3最新版破解方法
- HDU 2199 Can you solve this equation?(二分法求近似解)
- 打开文件和写文件的操作
- 浅谈WPF中的MVVM
- 基于C#的Windows定时关机系统的设计
- encodeURI 和 encodeURIComponent
- JAVA_final修饰符
- WeX5仿账本代码学习与分析
- 图像特征检测(Image Feature Detection)
- ALV demo:cl_salv_table
- ALV demo:cl_salv_table&nbsp…