使用Python 3将一个文件的内容复制到另一个文件中

Chi*_*rag 1 python file-handling python-3.x

我编写了以下代码,目的是将abc.txt的内容复制到另一个文件xyz.txt中

但声明b_file.write(a_file.read())似乎没有按预期工作.如果我用一些字符串替换a_file.read(),它(字符串)将被打印.

import locale
with open('/home/chirag/abc.txt','r', encoding = locale.getpreferredencoding()) as a_file:
    print(a_file.read())
    print(a_file.closed)

    with open('/home/chirag/xyz.txt','w', encoding = locale.getpreferredencoding()) as b_file:
        b_file.write(a_file.read())

    with open('/home/chirag/xyz.txt','r', encoding = locale.getpreferredencoding()) as b_file:
        print(b_file.read())
Run Code Online (Sandbox Code Playgroud)

我该怎么做?