python
import aiofiles
import asyncio
async def read_file():
async with aiofiles.open('file.txt', mode='r') as f:
contents = await f.read()
print(contents)
loop = asyncio.get_event_loop()
loop.run_until_complete(read_file())
python
import aiofiles
import asyncio
async def write_file():
async with aiofiles.open('file.txt', mode='w') as f:
await f.write('Hello, aiofiles!')
loop = asyncio.get_event_loop()
loop.run_until_complete(write_file())
python
import aiofiles
import asyncio
async def copy_file():
async with aiofiles.open('source.txt', mode='r') as src, \
aiofiles.open('destination.txt', mode='w') as dst:
contents = await src.read()
await dst.write(contents)
loop = asyncio.get_event_loop()
loop.run_until_complete(copy_file())