第一种
//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;
}
第二种
- (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;
}
第三种
[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *path = NSHomeDirectory();
上面的代码得到的是应用程序目录的路径,在该目录下有三个文件夹:Documents、Library、temp以及一个.app包!
该目录下就是应用程序的沙盒,应用程序只能访问该目录下的文件夹!!!
相关博文:http://zhouguangwu.sinaapp.com/detail.php?id=83