zoukankan      html  css  js  c++  java
  • 在iPone环境下要保存数据

    bool writeApplicationData(NSData *data, NSString *fileName)
        {
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            if (!documentsDirectory) {
                NSLog(@"Documents directory not found!");
                return NO;
            }
            NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
            return ([data writeToFile:appFile atomically:YES]);
        }
     
    NSData *applicationDataFromFile(NSString *fileName)
        {
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
            NSData *myData = [[[NSData alloc] initWithContentsOfFile:appFile] autorelease];
            return myData;
        }





    2个方法都是存储在/Documents/里面
  • 相关阅读:
    数组元素循环右移
    备忘录模式笔记
    调度算法(笔记)
    meta http-equiv的用法(转)
    常用Maven插件介绍(下)(转)
    常用Maven插件介绍(上)(转)
    maven命令
    JDK并发包
    线程基础
    Jav堆排序
  • 原文地址:https://www.cnblogs.com/chen1987lei/p/1682010.html
Copyright © 2011-2022 走看看