[英]NSFileManager: Copy a file atomically?
in my iPhone projects, I am currently copying files using NSFileManager
's -copyItemAtPath:toPath:error:
method. 在我的iPhone项目中,我目前正在使用
NSFileManager
的-copyItemAtPath:toPath:error:
方法复制文件。 However, the docs so not say anything about atomicity, so I might run into trouble if my app tries to read a file that is currently being replaced by another thread. 但是,文档没有说明原子性,所以如果我的应用程序试图读取当前被另一个线程替换的文件,我可能会遇到麻烦。 Is there a way to copy or replace a file atomically?
有没有办法以原子方式复制或替换文件? I am searching for something like
NSData
's -writeDataToFilr:atomically:
. 我正在寻找类似
NSData
的-writeDataToFilr:atomically:
.
How do you use NSFileManager
? 你如何使用
NSFileManager
? According to the docs , it says the following: 根据文档 ,它说如下:
In iOS and Mac OS X v 10.5 and later you should consider using
[[NSFileManager alloc] init]
rather than the singleton methoddefaultManager
.在iOS和Mac OS X v 10.5及更高版本中,您应该考虑使用
[[NSFileManager alloc] init]
而不是单例方法defaultManager
。 Instances ofNSFileManager
are considered thread-safe when created using[[NSFileManager alloc] init]
.使用
[[NSFileManager alloc] init]
创建时,NSFileManager
实例被认为是线程安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.