def modify_file(input_file, output_file):
try:
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
for line in infile:
modified_line = '《' + line.strip() + '》\n'
outfile.write(modified_line)
print(f"File '{input_file}' has been processed and saved to '{output_file}'.")
except FileNotFoundError:
print(f"Error: The file '{input_file}' was not found.")
except Exception as e:
print(f"An error occurred: {e}")
# 示例用法
input_filename = 'input.txt' # 輸入文件名
output_filename = 'output.txt' # 輸出文件名
modify_file(input_filename, output_filename)
|