2
我正在制作应用程序,需要将应用程序包中的某个文件复制到用户的应用程序支持文件夹。这是我实际使用的代码:将应用程序包中的文件复制到用户的应用程序支持文件夹
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *userpath = [paths objectAtIndex:0];
userpath = [userpath stringByAppendingPathComponent:executableName]; // The file will go in this directory
NSString *saveFilePath = [userpath stringByAppendingPathComponent:@"db.sqlite"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
[fileManager copyItemAtPath:[thisBundle pathForResource:@"db" ofType:@"sqlite"] toPath:saveFilePath error:NULL];
但是这不会复制任何东西,BTW这是一个Mac应用程序。
好吧得到了它使用:if([fileManager fileExistsAtPath:userpath] == NO) [fileManager createDirectoryAtPat h:userpath withIntermediateDirectories:YES属性:nil error:nil]; – pmerino
我有代码工作..但是有一个问题。假设文件大小为3.6 mb ..那么只有复制到文档目录的文件只有200kb ..它被部分复制。它有什么限制吗? –