1.文件操作(2) 代码 f = open('a.txt','a') # "a" 如果源文件不在,会自动创建 f.write('abc') result = f.read() print(result) f.close() # r read 能读,不能写,打开不存在的文件会报错 # w write 能写,不能读 # a add 能写,不会清空以前的内容,不能读
//C库函数读取文件的代码 I/O缓冲机制 C语言库函数写文件都是写在内存中,然后一次写入磁盘.提高了效率. 读写文件,不对系统进行操作,一般采用C语言库函数.移植可以在任何可以对C支持的操作系统,而不用修改. FILE *fopen(const char *path, const char *mode); mode 参数: r Open text file for reading. The stream is positioned at the beginning of the file