【问题标题】:initWithContentsOfURL what is the encoding?initWithContentsOfURL 是什么编码?
【发布时间】:2012-08-13 08:21:39
【问题描述】:

您好,我保存了一个 URL,该 URL 包含我将存储信息的目录的路径,现在我想检索信息但我不知道如何接收项目,我正在尝试使用 initWithContentsOfURL 但我不知道编码是什么吗?

这就是我保存 URL 的方式

//DirectoryPaths has the NSCAcheDirectory
 dirPath = [[directoryPaths objectAtIndex:0] URLByAppendingPathComponent:[NSString stringWithFormat:@"photos.jpg"]];

我现在如何获取 URL 的路径?我试过了

  NSString *pathToFile = [[NSString alloc] initWithContentsOfURL:dirPath
                                                 usedEncoding:nil
                                                        error:&error];

我不知道编码是什么,因为我没有使用编码来存储文件?

【问题讨论】:

    标签: objective-c xcode nsurl nsfilemanager initwithcontentsofurl


    【解决方案1】:

    我想你误会了; initWithContentsOfURL:usedEncoding:error: 从 URL 加载字符串。因此,您需要指定用于字符串的编码——UTF-8、ASCII 或类似的东西。

    要从您可能需要[dirPath path] 的 URL 获取磁盘路径。实际上,您可能只从 URL 加载,而不是硬编码本地磁盘行为。

    【讨论】:

      【解决方案2】:

      使用 NSUTF8StringEncoding 或 ASCII。这个对我有用。 :)

      【讨论】:

        猜你喜欢
        • 2011-07-14
        • 2017-07-28
        • 1970-01-01
        • 2011-09-24
        • 2011-07-21
        • 2018-07-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多