边读边写:
1 oldFile = open("itcast.txt", "r", encoding="utf-8") 2 newFile = open("itcast_backup.txt", "w", encoding="utf-8") 3 while True: 4 ret = oldFile.read(1024) 5 if ret: 6 newFile.write(ret) 7 else: 8 break 9 oldFile.close() 10 newFile.close()