获取沙盒中文件路径以及文件复制

//路径获取

NSString *path = [[NSBundle mainBundle]pathForResource:@"Phone"ofType:@"plist"];

 

//将沙盒中plist复制到document文件夹中

+ (BOOL)existingFileWithName:(NSString *)name type:(NSString *)type

{

    BOOL result = NO;

    

    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; //获取document文件夹路径

    

    

    NSString *nowPath = [NSString stringWithFormat:@"%@/%@.%@",path,name,type];

    

    NSString *sourcePath = [[NSBundlemainBundle]pathForResource:name ofType:type];

 

    //NSFileManager单例类

    if ([[NSFileManagerdefaultManager] fileExistsAtPath:nowPath]) {

        result = YES;

    }else{

        [[NSFileManagerdefaultManager] copyItemAtPath:sourcePath toPath:nowPath error:Nil];

    }

    

    NSLog(@"%@",path);

    return result;

}

posted @ 2013-10-24 20:33  Alien.chang  阅读(577)  评论(0编辑  收藏  举报