首页 > 移动平台 > 详细

IOS 文件,数据的读写

时间:2015-03-24 19:05:07      阅读:133      评论:0      收藏:0      [点我收藏+]

 

获取到 file 到名字方法

 NSArray *myPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

//NSDocumentDirectory  是表示沙盒里 document 文件夹的列表

//NSDocumentionDirectory  是 获取 沙盒里 library 里 documention里的文件夹列表

    NSString *path=[myPaths objectAtIndex:0]; // objectAtIndex : 为document 的文件列表

    NSString *filename=[path stringByAppendingPathComponent:@"properties.plist"];

 

 

-(IBAction)save:(id)sender

{

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

    NSString *path=[myPaths objectAtIndex:0];

    NSString *filename=[path stringByAppendingPathComponent:@"properties.plist"];

    

    NSMutableArray *array=[[NSMutableArray alloc] init];

    [array addObject:txt_name.text];

    [array addObject:txt_class.text];

    [array addObject:txt_id.text];

    [array writeToFile:filename atomically:YES];

    NSLog(@"come here");

}

-(IBAction)read:(id)sender

{

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

    NSString *path=[mypaths objectAtIndex:0];

    NSString *filename=[path stringByAppendingPathComponent:@"properties.plist"];

    if([[NSFileManager defaultManager] fileExistsAtPath:filename])

    {

        NSLog(@"it‘s ok");

        NSMutableArray *array=[[NSMutableArray alloc] initWithContentsOfFile:filename];

        txt_name.text=[array objectAtIndex:0];

        txt_class.text=[array objectAtIndex:1];

        txt_id.text=[array objectAtIndex:2];

    }

    

}

IOS 文件,数据的读写

原文:http://www.cnblogs.com/stuwan/p/4363652.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!