iOS應(yīng)用教程 實現(xiàn)文件拷貝
iOS應(yīng)用教程 實現(xiàn)文件拷貝是本文要介紹的內(nèi)容,由于ios文件對讀寫有限制,有關(guān)文件的讀寫描述,可以看iOS學(xué)習(xí)之路 文件操作。主要還是基于代碼實現(xiàn)
在實際開發(fā)中,我需要在工程中有一個sqlite數(shù)據(jù)庫文件,有相應(yīng)的數(shù)據(jù)結(jié)構(gòu)和初試數(shù)據(jù),在程序中應(yīng)用,在程序中又要對數(shù)據(jù)庫進行增加的操作,我們就需要把數(shù)據(jù)庫文件放到可以寫的目錄下,我采用的方法如下:
- -(void)copyFileDatabase
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:@"elimimation"];
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentLibraryFolderPath]) {
- NSLog(@"文件已經(jīng)存在了");
- }else {
- NSString *resourceSampleImagesFolderPath =[[NSBundle mainBundle]
- pathForResource:@"elimimation"
- ofType:@"sqlite"];
- NSData *mainBundleFile = [NSData dataWithContentsOfFile:resourceSampleImagesFolderPath];
- [[NSFileManager defaultManager] createFileAtPath:documentLibraryFolderPath
- contents:mainBundleFile
- attributes:nil];
- }
- }
- -(void)deleteFileDatabade
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:@"elimimation"];
- [[NSFileManager defaultManager] delete:documentLibraryFolderPath];
- }
小結(jié):iOS應(yīng)用教程 實現(xiàn)文件拷貝的內(nèi)容介紹完了,希望本文對你有所幫助!
轉(zhuǎn)自 http://wangjun.easymorse.com/?p=938