将 NSData 写入文件?

发布于 2024-09-16 12:43:00 字数 211 浏览 1 评论 0原文

我正在尝试将 nsdata 写入磁盘上的文件,我有以下代码,但它不起作用,我做错了什么吗?

Boolean result = [data writeToFile:@"/Users/aryaxt/Desktop/test2.avi" atomically:YES];

test2.avi 不存在,我假设 writeToFile 会为我创建它

I am trying to write an nsdata to a file on my disk, I have the following code and it doesn't work, am i doing anything wrong?

Boolean result = [data writeToFile:@"/Users/aryaxt/Desktop/test2.avi" atomically:YES];

test2.avi doesn't exist, I am assuming that writeToFile would create it for me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-09-23 12:43:00

尝试使用 :

NSError *error = nil;
path=@"/Users/aryaxt/Desktop/test2.avi";
[data writeToFile:path options:NSDataWritingAtomic error:&error];
NSLog(@"Write returned error: %@", [error localizedDescription]);

这会告诉您写入失败的原因。

Try using :

NSError *error = nil;
path=@"/Users/aryaxt/Desktop/test2.avi";
[data writeToFile:path options:NSDataWritingAtomic error:&error];
NSLog(@"Write returned error: %@", [error localizedDescription]);

That'll tell you why the write is failing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文