zoukankan      html  css  js  c++  java
  • iOS获取文件路径

    文件在工程的存放结构

     

    具体代码如下:

    //文件路径
    NSBundle *bundle = [NSBundle bundleForClass:[PopQuestionUIView class]];
    NSURL *url = [bundle URLForResource:@"Resources" withExtension:@"bundle"];
    NSBundle *resBundle = [NSBundle bundleWithURL:url];
    NSString *filePath = [resBundle pathForResource:@"popQuestionLocalData" ofType:@"txt"];
    
    // NSData类方法读取数据
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"NSData类方法读取的内容是:%@", jsonString);
        
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                            options:NSJSONReadingMutableContainers
                                                              error:&err];
    

      

     

  • 相关阅读:
    android openGl视频
    《jQuery权威指南》学习笔记之第2章 jQuery选择器
    RobHess的SIFT源码分析:综述
    building android/ubuntu-touch on 32bit machine
    Android开发(24)---安卓中实现多线程下载(带进度条和百分比)
    创建Sdcard
    POJ 1033 Defragment
    [C++STDlib基础]关于C标准输入输出的操作——C++标准库头文件<cstdio>
    机器学习实战决策树之眼镜男买眼镜
    protubuffer for windows配置指南!
  • 原文地址:https://www.cnblogs.com/hacjy/p/6007226.html
Copyright © 2011-2022 走看看