2011-10-20 35 views

回答

184

是的。它會。

以下是一些要傳遞30個字符限制的字符。

+47

+1「記錄」你多餘的字符:) – Julian

+17

無論你做原子與否沒有按沒關係;在任何一種情況下,文件都將被新數據完全覆蓋。 –

+0

啊,但對我來說,它失敗了,原始文件完好無損。由於writeToFile不會返回NSError,因此如何調查失敗?這可能是一個權限問題,但我不能確定。我的代碼作爲安裝程序插件包運行,需要root權限的安裝包 - 我不知道如何驗證/打印我的代碼運行的權限。 –

3

方法writeToFile:atomically:總是覆蓋文件,不管atomically:是或否。

Apple docs(NSData的,部分 「保存數據」)的信息:

The NSData class and its subclasses provide methods to quickly and easily save their contents to disk. To minimize the risk of data loss, these methods provide the option of saving the data atomically. Atomic writes guarantee that the data is either saved in its entirety, or it fails completely. The atomic write begins by writing the data to a temporary file. If this write succeeds, then the method moves the temporary file to its final location.

沒有一個字有關,如果文件存在檢查。

例如,對於方法copyItemAtPath:toPath:error:docs(的NSFileManager,部分討論)專門寫了這樣的檢查:

If a file with the same name already exists at dstPath, this method stops the copy attempt and returns an appropriate error.