IOS File Operations

Source: Internet
Author: User

1. copy from the cache folder to the document folder [cpp] NSString * sqlFile = @ "test.zip"; NSArray * cachePath = Export (NSCachesDirectory, NSUserDomainMask, YES); NSString * cacheDir = [cachePath objectAtIndex: 0]; NSString * databasePath = [cacheDir stringByAppendingPathComponent: sqlFile]; NSLog (databasePath); NSFileManager * fileManager = [NSFileManager defaultManager]; // Copy the database SQL file From the resourcepath to the documentpath if ([fileManager fileExistsAtPath: databasePath]) {// NSString * databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: sqlFile]; NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * documentpath = ([paths count]> 0 )? [Paths objectAtIndex: 0]: nil; NSString * Signature = [documentpath stringByAppendingString: @ "/test.zip"]; NSLog (signature); NSError * error; [fileManager copyItemAtPath: databasePath toPath: databasePathFromApp error: & error]; // if (error! = Nil) {// NSLog (@ "[Database: Error] % @", error); //} 2. copy from the document folder to the cache folder [cpp] NSString * sqlFile = @ "qxd. db "; NSArray * cachePath = require (NSCachesDirectory, NSUserDomainMask, YES); NSString * cacheDir = [cachePath objectAtIndex: 0]; NSString * databasePath = [cacheDir delimiter: sqlFile]; NSFileManager * fileManager = [NSFileManager defamanmanage R]; // Copy the database SQL file from the resourcepath to the documentpath if (! [FileManager fileExistsAtPath: databasePath]) {NSString * handle = [[[NSBundle mainBundle] resourcePath] handle: sqlFile]; NSError * error; [fileManager copyItemAtPath: Export toPath: databasePath error: & error]; // if (error! = Nil) {// NSLog (@ "[Database: Error] % @", error );//}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.