这是我的代码。
NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"Songs"];
NSString *fromPath=[[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"abc"];
NSString *strdestination = [fromPath stringByAppendingPathComponent:@"sg.mp3"];
NSError *Error;
if([[NSFileManager defaultManager]fileExistsAtPath:strdestination]){
if([[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error]==NO){
UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
}
else{
UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"Not copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
}
}
我收到错误徽标:
错误域 = NSCocoaErrorDominCode = 516“操作无法完成。(可可箭头 516。)”用户信息 = 0x681abf0
NSUnderlyingError =0x681b920 "操作无法完成。文件存在"
abc 文件夹中没有歌曲名称“sg.mp3”,但我仍然收到文件存在错误。不知道我哪里做错了?