方法可以有三个,但其实是一个方法,因为不同的方法都是文件存储的方法,文件修改就只有一个方法: 将文件导入list后,重新写入文件(另一个文件或者当前文件) 1.当前文件读取后,list修改内容,写入另一个新建文件 f = open("D:\data\k1.TXT","r") ff= open ("D:\data\\new\k1.TXT","w") new=[] for line in f: new.append(line) n
//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