zoukankan      html  css  js  c++  java
  • 【旧事重提】iOS中文件读写

    ---恢复内容开始---

    1. 读取文件  (本地 UTF-8编码的文本文件

        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"json"];

        NSString *str =[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

        //NSData *data = [NSData dataWithContentsOfFile:filePath];

        //NSString *textFile  = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        id jsonObj = [str jsonObject];

        NSArray *item = [jsonObj objectForKey:@"data"];

        NSLog(@"arr %lu %@", (unsigned long)[item count], item);

     

    2. 写入文件

    //Document 目录

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];需要的路径

    NSString *fileD = [documentSDirectory stringByAppendingPathComponent:@"xxx.txt"];

     

     NSString* fileName = [[filePath objectAtIndex:0] stringByAppendingPathComponent: DBNAME];

       [fileData writeToFile:fileName atomically:YES]

    ---恢复内容结束---

  • 相关阅读:
    Python标准异常topic
    文件打开的模式和文件对象方法
    python中常用的一些字符串
    zabbix3.2.0beta2 监控模版
    人工智能 --test
    Jenkins 2.7.3 LTS 发布
    Python中的socket 模块
    hibenater返回map
    去掉JavaScript Validator
    properties工具类
  • 原文地址:https://www.cnblogs.com/lee4519/p/4279088.html
Copyright © 2011-2022 走看看