【问题标题】:How Reading From Files and URLs (.plist or .txt)如何读取文件和 URL(.plist 或 .txt)
【发布时间】:2012-07-18 23:54:58
【问题描述】:

我需要读取一个文件。 plist 或。来自一个网址的txt

例如。

http://www.nordenmovil.com/BuscadorTopTen/carros.plist

http://www.nordenmovil.com/BuscadorTopTen/texto.txt

NSString * path = @ "www.nordenmovil.com/BuscadorTopTen/carros.plist";
     NSError * error;
     NSString * stringFromFileAtPath = [[NSString alloc]
                                       initWithContentsOfFile: path
                                       encoding: NSUTF8StringEncoding
                                       error: & error];
     if (stringFromFileAtPath == nil) {
         / / An error occurred
         NSLog (@ "Error reading file at% @ \ n% @",
               path, [error localizedFailureReason]);
     }
     NSLog (@ "% @", stringFromFileAtPath);

【问题讨论】:

    标签: ios xcode nsdata nsurl


    【解决方案1】:

    所以你使用 NSURLConnection,你给它 URL,你得到一个数据对象。然后,您需要将该对象转换为您可以处理的东西——也就是说,您可以找到可以将该对象转换为所需格式的 iOS 类。假设数据是图像。然后你会使用:

    [UIImage imageWithData:];

    所有其他对象都类似

    【讨论】:

    猜你喜欢
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 2014-04-21
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多