c python shell文件读写
来源:互联网 发布:自动注音软件 编辑:程序博客网 时间:2024/05/19 22:56
- linux
- python
- shell
linux
#include <stdio.h>//#include <sys/types.h>//#include <sys/stat.h>#include <fcntl.h> //headfile of open#include <errno.h> //headfile of errno#include <string.h> //headfile of sterror#include <unistd.h> //headfile of readvoid readFile(){ char filepath[] = "/home/zijing/readfile.txt"; int fd = open(filepath, O_RDONLY); if(fd == -1){ printf("read error, %s --> %s\n",filepath, strerror(errno)); return; }// printf("success fd = %d\n", fd); char buf[100]; memset(buf,0,sizeof(buf)); while(read(fd, buf, sizeof(buf) - 1) > 0){ printf("%s\n", buf); memset(buf, 0, sizeof(buf)); } printf("%s\n",buf); close(fd);}void writeFile(){ char filepath[] = "/home/zijing/writefile.txt"; int fd = open(filepath, O_RDWR | O_APPEND); if (fd == -1){ printf("write error, %s -- > %s\n", filepath, strerror(errno)); return; }// printf("success fd = %d\n", fd); char buf[100]; memset(buf, 0, sizeof(buf)); strcpy(buf, "hello linux from c\n"); write(fd,buf,strlen(buf)); close(fd);}int main(int arg, char *args[]) { readFile(); writeFile(); return 0;}
python
def readfileOnce(): file = open('/home/zijing/readfile.txt', encoding='utf-8') data = file.read() file.close() print(data,end='') #end line without '\n'def readfileBylist(): file = open('/home/zijing/readfile.txt','r',encoding='utf-8') for line in file.readlines(): print(line,end = '') #end line without '\n' file.close()def readfileBylines(): # high efficent file = open('/home/zijing/readfile.txt','r',encoding='utf-8') for line in file: print(line,end = '') #end line without '\n' file.close()def writefile(): file = open('/home/zijing/writefile.txt','a',encoding='utf-8') file.write("hello linux from python\n") file.close()readfileOnce()readfileBylist()readfileBylines()writefile()
shell
#!/bin/bash#sign: 2017/9/17 zijing#funtion: file opreate of read and fileFILEPATH="/home/zijing/readfile.txt"FILEWRITEPATH="/home/zijing/writefile.txt"function readfile(){ cat $FILEPATH | while read line; do echo $line; done}function writefile(){ echo "hello linux from shell" >> $FILEWRITEPATH}readfilewritefile
阅读全文
0 0
- c python shell文件读写
- shell 文件读写
- shell读写ini文件
- shell读写大文件
- python--python读写文件
- 【C/C++】文件读写
- c python shell获得文件路径以及所有的文件
- linux shell编程读写文件
- shell 脚本读写处理文件
- linux shell校验读写文件
- linux shell编程读写文件
- Python读写Unicode文件
- python Ini文件读写
- Python读写文件
- Python读写文件
- Python读写ini文件
- Python读写文件
- Python读写文件
- 使用内联标签时应该注意的line-height
- Java 多线程(PART VIII)synchronized(I)
- [T13365]他
- python库函数-datetime
- Java中运算符的优先级
- c python shell文件读写
- shell编程向函数传递数组
- SSM框架入门和搭建
- Cookie/Session机制详解
- URAL 1089|Verification with a Vocabulary|暴力
- 数据库建立远程链接的方法
- qbxt Day 6 搜索+乱搞+差分约束
- Spring面向切面编程——什么是面向切面编程
- 《着色器和屏幕特效》读书笔记第八章-用Unity的渲染纹理实现屏幕特效