#Python3 os.fsync() 方法
#强制将文件描述符为fd的文件写入硬盘。在Unix, 将调用fsync()函数;在Windows, 调用 _commit()函数。
====================
#!/usr/bin/python3
import os, sys
# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# 写入字符串
os.write(fd, "This is test".encode())
# 使用 fsync() 方法.
os.fsync(fd)
# 读取内容
os.lseek(fd, 0, 0)
str = os.read(fd, 100)
print ("读取的字符串为 : ", str)
# 关闭文件
os.close( fd)
print ("关闭文件成功!!")
|