zoukankan      html  css  js  c++  java
  • IOS 读取项目中的文件方法

    在项目中,经常需要读取配置文件,现在就来看看读取plist配置文件的代码

    //读取项目下的文件路径
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"fileName" ofType:@"plist"];
    
    //可转换成URL
    NSURL *url = [NSURL fileURLWithPath:path];
    
    //如NSXML就需要提供URL地址
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    
    //换成NSData
    NSData *data = [[NSData alloc]initWithContentsOfFile:path];

     

    //可直接转换成对应文件格式
    //当plist文件为字典是可用以下方法
    NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:plistPath];
    //当plist文件为数组类型可以使用以下方法
    NSArray *array = [[NSArray alloc] initWithContentsOfFile:plistPath];
  • 相关阅读:
    Picture
    wolf and rabbit
    十进制转换为二进制(一直不会算的)
    各种排序
    折线分割平面
    字母数
    1001
    Primes
    大数的减法神秘数
    转: Windows Internet WinINet 学习笔记(2)
  • 原文地址:https://www.cnblogs.com/oscar1987121/p/5229441.html
Copyright © 2011-2022 走看看