边读边写:

 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()

 

posted on 2019-05-22 17:50  浮生若梦-平  阅读(76)  评论(0编辑  收藏  举报