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;
    }
  • 相关阅读:
    《python基础教程 》第二章 读书笔记
    hdu 4462 Scaring the Birds 解题报告
    hud 4454 Stealing a Cake 解题报告
    uva 532 Dungeon Master
    《python基础教程 》第一章 读书笔记
    开源项目资源站点
    syslog() 函数简单解析
    ftruncate()函数
    Mysql数据库函数
    int mysql_options() mysql_real_connect() mysql_real_query()/mysql_real_escape_string
  • 原文地址:https://www.cnblogs.com/qingjoin/p/2576365.html
Copyright © 2011-2022 走看看