# 写入文件
def write_to_file(filename, content):
with open(filename, 'w') as file:
file.write(content)
print("Content has been written to", filename)
# 读取文件
def read_from_file(filename):
try:
with open(filename, 'r') as file:
content = file.read()
print("Content read from", filename, ":", content)
except FileNotFoundError:
print("File not found:", filename)
# 测试写入文件
write_to_file("example.txt", "This is an example content.")
# 测试读取文件
read_from_file("example.txt")