首页 > 代码库 > IOS常用获取沙盒路径,URL方法

IOS常用获取沙盒路径,URL方法

获得沙盒Documents文件夹路径
1:
<span style="font-size:18px;"> NSArray *searchPach = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *path1 = [[searchPach firstObject] stringByAppendingPathComponent:@"file1"];</span>
   
2:
  
 NSFileManager *manager = [NSFileManager defaultManager];
    NSURL *url = [[manager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
    NSURL *path2 = [url URLByAppendingPathComponent:@"MyDocument"];
    UIManagedDocument *managedDocument = [[UIManagedDocument alloc]initWithFileURL:path2];

3:
 
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/text.txt”];

IOS常用获取沙盒路径,URL方法