将 NSData 写入文件的最简单方法

问题描述:

NSData *data;
data = [self fillInSomeStrangeBytes];

我现在的问题是如何以最简单的方式将此 data 写入文件.

My question is now how I can write this data on the easiest way to an file.

(我已经有一个 NSURL file://localhost/Users/Coding/Library/Application%20Support/App/file.strangebytes)

(I've already an NSURL file://localhost/Users/Coding/Library/Application%20Support/App/file.strangebytes)

NSData 有一个名为 writeToURL:atomically: 的方法,它完全符合您的要求.查看文档code>NSData 看看如何使用它.

NSData has a method called writeToURL:atomically: that does exactly what you want to do. Look in the documentation for NSData to see how to use it.