我想将文件从应用程序 NSBundle 复制到 Documents 目录。
我怎么无法让这段代码工作:
-(NSString*)copyFile:(NSString*)name{
NSString *storePath = [[[appDelegate applicationDocumentsDirectory] absoluteString] stringByAppendingPathComponent:name];
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"recordTest" ofType:@"caf"];
if (defaultStorePath) {
if ([fileManager fileExistsAtPath:defaultStorePath]) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:&error];
NSLog(@"Error: %@)" , [error localizedDescription]);
}
}
}
return storePath;
}
此打印操作无法完成。
更详细地说:
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0xd629530 {NSUserStringVariant=(
Copy
), NSFilePath=/var/mobile/Applications/D0183043-3FD2-4341-8DA4-E1D140E556F6/test.app/recordTest.caf, NSDestinationFilePath=file:/localhost/var/mobile/Applications/D0183043-3FD2-4641-8DA4-E5D140E556F6/Documents/recordTest.caf, NSUnderlyingError=0xd629970 "The operation couldn’t be completed. No such file or directory"}
如果我在复制前检查,我不明白为什么没有这样的文件。
有任何想法吗 ?
谢谢