您的位置:首页 > 运维架构

Error The operation couldn’t be completed. (Cocoa error 516.)

2013-11-21 19:29 1386 查看
This is very common error that happens when you try to create a file on the file system and a file with the same name already exists. You can avoid that by checking whether a file with the name already exists or not. If it does exists then remove
it and try to create again.
Error 516 is NSFileWriteFileExistsError - You can't move a file to a place where a file already exists.
The below code does not check for this and can lead to above error:
            NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSString *destSpecFile = [NSString stringWithFormat:@"%@/%@", docDir,gallerySpecFile];

           
            NSError *err;

                   
            NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:gallerySpecFile];
            CCLOG(@"Src %@",srcPath);
            CCLOG(@"Descr %@",destSpecFile);

           
            [[NSFileManager defaultManager] copyItemAtPath:srcPath

                                                    toPath:destSpecFile

                                                     error:&err];
Before attempting the copyItemAtPath, check the destination file and if there, remove it.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐