"""
文件的打开
mode: r w a
读写:
r+
w+
a+
操作图片,音频,视频...
rb
wb
文件的读写
read
readline
readlines
文件的关闭
f.close()
逐行读取文件的方式:
for s in f:
print(s)
-----------
s = f.readline()
while s != '':
print(s)
s = f.readline()
文件的复制:
1.读取目标文件中的数据
打开目标文件
读取所有内容
2.将读取到的数据写入新文件中 (注意新文件名的处理)
打开新文件
将读取到的内容写入到新文件中
关闭所有文件
def copyfile(oldfile):
"""
f = open('poem.txt',mode='r',encoding='utf-8')#poem.txt是文件名
s = f.read(5)
print(s)
# 在之前读取结束的位置,继续读取
s = f.read(5)
print(s)
f.close()
# 循环读取逐行读取某个文件中所有的内容
f = open('demo01_知识回顾.py','r',encoding='utf-8')#demo01_知识回顾.py是文件名,‘r’读
# for s in f:
# print(s,end='')
# f.close()
s = f.readline()
while s != '':
print(s,end='')
s = f.readline()#一行一行读
f.close()