首页 > 移动平台 > 详细

iOS 沙盒的用法

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

创建沙盒的路径:

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 沙盒的用法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!