zoukankan      html  css  js  c++  java
  • objc iOS 数组存入程序文件 arrayWithContentsOfFile

    -(void)writeFileArray
    {
        int i;
        NSLog(@"writeFileArray\n");
        //新建userinfomation数组用来存一些信息
        NSArray *userinfomation = [NSArray arrayWithObjects:@"One",@"Two",@"Three",@"four",@"five",@"six",@"seven",@"name",@"school",@"class",@"age",@"imformation",@"last",nil];   
        for(i = 0; i<12; i++)
        {
            NSLog(@"%i %@",i+1,[userinfomation objectAtIndex:i]);
        }
        //把userinfomation这个数组存入程序指定的一个文件里
        [userinfomation writeToFile:[self documentsPath:@"usefile.txt"] atomically:YES];
           
    }
    
    -(void)readFileArray
    {
        NSLog(@"readfile........\n");
        //dataPath 表示当前目录下指定的一个文件 data.plist 
        //NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; 
        //filePath 表示程序目录下指定文件 
        NSString *filePath = [self documentsPath:@"usefile.txt"]; 
        //从filePath 这个指定的文件里读
        NSArray *userinfo = [NSArray arrayWithContentsOfFile:filePath];
        NSLog(@"%@",[userinfo objectAtIndex:1] );
         
    }
    
    -(NSString *)bundlePath:(NSString *)fileName {
        return [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
    }
    
    -(NSString *)documentsPath:(NSString *)fileName {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        return [documentsDirectory stringByAppendingPathComponent:fileName];
    }
    
    -(NSString *)documentsPath {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        return documentsDirectory;
    }
  • 相关阅读:
    Redis 之服务器集群配置
    Redis 之持久化(rdb、aof)
    Redis 之消息发布与订阅(publish、subscribe)
    Redis事物及锁的运用
    Redis 之hash集合结构及命令详解
    对Ul下的li标签执行点击事件——如何获取你所点击的标签
    .net 面试题(3)
    SQL Server 系统时间
    分布式内存对象缓存 memcached
    MVC 模板页和布局
  • 原文地址:https://www.cnblogs.com/qingjoin/p/2576365.html
Copyright © 2011-2022 走看看