首页 > 其他 > 详细

文件拷贝

时间:2020-02-07 00:12:10      阅读:84      评论:0      收藏:0      [点我收藏+]
# 复制文件小脚本

source_file = rD:\py1912\demo\tanchishe.py
target_file = rD:\py1912\demo\temp.py

# 分别打开文件对象
source = open(source_file,rb)
target = open(target_file,wb)

# 从源文件中读取指定数量字节 1024B
buffer_size = 10  # 缓冲区大小
data = source.read(buffer_size)

# 只要数据对象不是空字节对象,我们就认为还有数据
while data != b"":
    # 向目标文件中写入数据
    target.write(data)
    # 继续读取数据
    data = source.read(buffer_size)

# 关闭文件对象
source.close()
target.close()

 

文件拷贝

原文:https://www.cnblogs.com/libragyf/p/12271326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!