码迷,mamicode.com
首页 > 其他好文 > 详细

NSSearchPathForDirectoriesInDomains用法

时间:2015-09-09 16:34:42      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

//返回文件路径

-(NSString *)getDocumentPath

{

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

    NSString *docPath=[mypath objectAtIndex:0];

    NSLog(@"%@",mypath);

    NSString *plistPath=[docPath stringByAppendingPathComponent:@"student。plist"];

    return plistPath;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    //调用方法,获取文件路径

    NSString *path=[self getDocumentPath];

    NSLog(@"%@",path);

    //建立文件管理者,判断文件是否存在如果不存在重新创建,然后回馈是否创建成功

    NSFileManager *fileManager=[NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath:path])

    {

        NSLog(@"没有指定文件,需要创建");

        BOOL isOK=[fileManager createFileAtPath:path contents:nil attributes:nil];

        if (isOK)

        {

            NSLog(@"创建成功");

        }

        else

        {

            NSLog(@"创建失败");

        }

    }

}

 

NSSearchPathForDirectoriesInDomains用法

标签:

原文地址:http://www.cnblogs.com/OIMM/p/4794818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!