//Returns the path to the application's Documents directory. // 方法1 iOS4.0版本以上的可以使用该方法获取url - (NSURL *)applicationDocumentsDirectory_New { //Availability: iOS 4.0 and later NSURL *documentsDictoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; NSURL *storeURL = [documentsDictoryURL URLByAppendingPathComponent:@"Data.sqlite"]; return storeURL; }//方法2 iOS4.0版本以下的可以使用该方法获取url
- (NSURL *)applicationDocumentsDirectory_Old { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//程序文件夹主目录 NSString *documentsDirectory = [paths objectAtIndex:0];//Document目录 NSString *storePath = [documentsDirectory stringByAppendingPathComponent:@"Data.sqlite"]; NSURL *storeURL = [NSURL fileURLWithPath:storePath]; return storeURL; }
//方法3 获取文件中的Image地址及UIImage
NSString*imagePath = [[[NSBundlemainBundle] resourcePath] stringByAppendingPathComponent:@"Image"]; imagePath = [artistImagePath stringByAppendingPathComponent:@"bg"]; imagePath = [artistImagePath stringByAppendingPathComponent:@"bg.png"]; NSLog(@"%@", imagePath); UIImage* pic = [UIImage imageWithContentsOfFile: imagePath]; //输出:/Users/test/Library/Application Support/iPhone Simulator/4.1/Applications/Test.app/Image/bg/bg.png