1.二进制读取模式
file_name = "C:/Users/cheng/Desktop/can.jmx"
with open(file_name, 'rt', ) as can:
print(can.read())
执行结果
rb 读取模式
file_name = "C:/Users/cheng/Desktop/can.jmx"
with open(file_name, 'rb', ) as can:
print(can.read())
执行结果
file_name = "C:/Users/cheng/Desktop/can.jmx"
with open(file_name, 'rb', ) as can:
print(can.read(100))
执行结果
将读取到的内容写入到文件
file_name = "C:/Users/cheng/Desktop/can.jmx"
with open(file_name, 'rb', ) as can:
new_name = 'to.jmx'
with open(new_name, 'wb') as cheng:
cc = 1024 * 100
while True:
content = can.read(cc)
if not content:
break
cheng.write(content)
执行结果:
|