码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 沙盒的用法

时间:2015-04-06 15:46:50      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:ios   沙盒   数据存储   

创建沙盒的路径:

NSFileManager *fileManager = [NSFileManager defaultManager]; 
NSArray *documentPaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSLog(@"documentPath %@",documentPaths); 
NSString *ourDocumentPath=[documentPaths objectAtIndex:0]; 
NSLog(@"ourDocumentPath= %@",ourDocumentPath); 
NSString *fileName=[ourDocumentPath stringByAppendingPathComponent:@"MOVeee"]; 
[fileManager createDirectoryAtPath:fileName withIntermediateDirectories:YES attributes:nil error:nil];


添加文件夹,添加文件


    NSString *testPath = [testDirectory stringByAppendingPathComponent:@"test00.txt"];  
    NSString *testPath2 = [testDirectory stringByAppendingPathComponent:@"test22.txt"];  
    NSString *testPath3 = [testDirectory stringByAppendingPathComponent:@"test33.txt"];  
    NSString *string = @"写入内容,write String";
    [fileManager createFileAtPath:testPath contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
    [fileManager createFileAtPath:testPath2 contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
    [fileManager createFileAtPath:testPath3 contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];

获取目录列里所有文件名

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSString *documentsDirectory = [paths objectAtIndex:0];  
    NSLog(@"documentsDirectory%@",documentsDirectory);  
    NSFileManager *fileManage = [NSFileManager defaultManager];  
    NSString *myDirectory = [documentsDirectory stringByAppendingPathComponent:@"test"];  
    NSArray *file = [fileManage subpathsOfDirectoryAtPath: myDirectory error:nil]; 
    NSLog(@"%@",file);  
    NSArray *files = [fileManage subpathsAtPath: myDirectory ]; 
    NSLog(@"%@",files);

iOS 沙盒的用法

标签:ios   沙盒   数据存储   

原文地址:http://blog.csdn.net/yangchen9931/article/details/44901749

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!