NSString *realPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/xx.sqlite"];NSError *error;
NSURL *url = [NSURL URLWithString:realPath];
if ([fileManager fileExistsAtPath:realPath]) {
NSLog(@"文件存在");
[fileManager removeItemAtURL:url error:&error];//删除不了哦
NSLog(@"error=%@",error);
}
if (![fileManager copyItemAtPath:sourcePath toPath:realPath error:&error])
{//只要文件存在就不能复制,也不能覆盖。
NSLog(@"%@",[error localizedDescription]);
}
else {
NSLog(@"成功复制%@到路径:%@。",sourcePath,realPath);
}
NSURL *url = [NSURL URLWithString:realPath];
if ([fileManager fileExistsAtPath:realPath]) {
NSLog(@"文件存在");
[fileManager removeItemAtURL:url error:&error];//删除不了哦
NSLog(@"error=%@",error);
}
if (![fileManager copyItemAtPath:sourcePath toPath:realPath error:&error])
{//只要文件存在就不能复制,也不能覆盖。
NSLog(@"%@",[error localizedDescription]);
}
else {
NSLog(@"成功复制%@到路径:%@。",sourcePath,realPath);
}
直接用NSString的路径删除啊。请参考如下:
http://blog.csdn.net/cxsjabcabc/article/details/7167729