iOS应用教程 实现文件拷贝

移动开发 iOS
本文介绍的是iOS应用教程 实现文件拷贝,主要是对文件的操作。我们来看内容。

iOS应用教程 实现文件拷贝是本文要介绍的内容,由于ios文件对读写有限制,有关文件的读写描述,可以看iOS学习之路 文件操作。主要还是基于代码实现

在实际开发中,我需要在工程中有一个sqlite数据库文件,有相应的数据结构和初试数据,在程序中应用,在程序中又要对数据库进行增加的操作,我们就需要把数据库文件放到可以写的目录下,我采用的方法如下:

  1. -(void)copyFileDatabase   
  2. {   
  3.     NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);   
  4.     NSString *documentsDirectory = [paths objectAtIndex:0];       
  5.     NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:@"elimimation"];   
  6.     if ([[NSFileManager defaultManager] fileExistsAtPath:documentLibraryFolderPath]) {   
  7.         NSLog(@"文件已经存在了");   
  8.     }else {   
  9.         NSString *resourceSampleImagesFolderPath =[[NSBundle mainBundle]   
  10.                                                    pathForResource:@"elimimation"   
  11.                                                    ofType:@"sqlite"];   
  12.         NSData *mainBundleFile = [NSData dataWithContentsOfFile:resourceSampleImagesFolderPath];   
  13.         [[NSFileManager defaultManager] createFileAtPath:documentLibraryFolderPath   
  14.                                                     contents:mainBundleFile   
  15.                                                   attributes:nil];   
  16.     }  
  17.  
  18. }   
  19. -(void)deleteFileDatabade   
  20. {   
  21.     NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);   
  22.     NSString *documentsDirectory = [paths objectAtIndex:0];       
  23.     NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:@"elimimation"];   
  24.     [[NSFileManager defaultManager] delete:documentLibraryFolderPath];   

小结:iOS应用教程 实现文件拷贝的内容介绍完了,希望本文对你有所帮助!

转自 http://wangjun.easymorse.com/?p=938

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-11-16 15:47:04

AdobeAIRiOS应用

2010-02-06 17:09:29

C++文件拷贝

2011-07-08 14:58:16

iPhone Xcode iOS

2011-05-23 17:00:29

2021-11-24 08:41:52

BufferedWriJavaBufferedRea

2014-04-02 10:29:12

iOS 7模糊效果

2011-08-09 10:27:41

iOS剪贴板

2011-08-11 15:12:06

Xcode检验

2011-07-28 16:06:34

IOS 应用程序 资源

2012-01-18 13:51:39

2011-06-28 10:23:27

UIViewiOS

2015-12-09 14:00:41

ios应用

2018-09-26 14:37:17

JavaScript前端编程语言

2017-12-20 15:11:48

iOS缓存文件断点机制

2018-10-25 15:13:23

APP脱壳工具

2011-07-22 16:29:53

IOS Demo CD

2011-07-28 09:49:50

IOS IOS 4 UI

2022-11-07 11:37:27

深拷贝浅拷贝底层

2011-11-16 15:08:30

AdobeAIRiOS应用

2011-06-27 16:00:34

视频教程Cocoa TouchiOS应用
点赞
收藏

51CTO技术栈公众号