关于获取documents路径

//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
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值