iPhone - NSData from local file's URL

前端 未结 5 1401
说谎
说谎 2021-01-30 19:39

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

5条回答
  •  一个人的身影
    2021-01-30 19:55

    // Given some file path URL: NSURL *pathURL
    // Note: [pathURL isFileURL] must return YES
    NSString *path = [pathURL path];
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
    

    Swift code:

    let data = FileManager.default.contents(atPath: path)
    

提交回复
热议问题