iPhone - 来自本地文件URL的NSData [英] iPhone - NSData from local file's URL
本文介绍了iPhone - 来自本地文件URL的NSData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSURL
对象,它为我提供了本地文件的路径(在文档文件夹中)。我想用这个文件的内容填充 NSData
对象。尝试使用 dataWithContentsOfURL:
但这失败了。我知道该文件存在,因为iPhone SDK
返回路径。
I have a NSURL
object which gives me the path of a local file (in documents folder). I want to populate an NSData
object with the contents of this file. Tried using dataWithContentsOfURL:
but this fails. I know the file exists because the iPhone SDK
returns the path.
有人可以告诉我如何获得本地文件的 URL
中的 NSData
对象?
Can someone please tell me how I can get an NSData
object from the URL
of a local file?
谢谢。
推荐答案
// Given some file path URL: NSURL *pathURL
// Note: [pathURL isFileURL] must return YES
NSString *path = [pathURL path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
这篇关于iPhone - 来自本地文件URL的NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文