How does FileLock work?

前端 未结 5 2043
-上瘾入骨i
-上瘾入骨i 2020-11-30 11:14

I\'ve been trying to use FileLock to get exclusive access to a file in order to:

  • delete it
  • rename it
  • write to it

5条回答
  •  我在风中等你
    2020-11-30 12:11

    The delete and rename operations are performed by the operating system and are atomic (on most operating systems), so no locking is required.

    To write a string to file, it would be simpler to write to a temporary file first (e.g. foo.tmp) and then rename it once it is ready.

提交回复
热议问题