案例:复制大文件

s_file = open('test1.txt', 'rb')
d_file = open('test2.txt', 'wb')
while True:
    content = s_file.read(1024)  # 每次只读取1024个字符
    if len(content) == 0:   # 说明分段读取完毕
        break  # 跳出循环
    d_file.write(content)  # 向目标文件写入分段读取的内容
s_file.close()
d_file.close()

猜你喜欢

转载自www.cnblogs.com/dangrui0725/p/9420791.html