ios文件管理---沙盒

来源:互联网 发布:对比两组数据的差异性 编辑:程序博客网 时间:2024/05/17 04:22

// 获得应用程序沙盒的Documents文件夹路径

   NSString *documentPaths=NSSearchPathForDirectoriesInDomains[(NSDocumentDirectory,NSUserDomainMask,YESobjectAtIndex:0];

//输出沙盒Documents文件夹路径

    NSLog(@"Documents path: %@",documentPath);

    

    // 获得应用程序沙盒的Caches文件夹路径

    NSString *CachesPath=NSSearchPathForDirectoriesInDomains[(NSCachesDirectory,NSUserDomainMask,YESobjectAtIndex:0];

//输出沙盒Caches 文件夹路径

    NSLog(@"Caches path: %@",CachesPath);

    

    // 获得应用程序沙盒的Downloads文件夹路径

    NSString *loadPathsPath=NSSearchPathForDirectoriesInDomains[(NSDownloadsDirectory,NSUserDomainMask,YESobjectAtIndex:0];

//输出沙盒Downloads文件夹路径

    NSLog(@"Downloads path: %@",loadPathsPath);



//第二种获取沙盒下路径的方式

    

    // 获得应用程序沙盒的home文件夹路径

    NSString *homePath= NSHomeDirectory();

    

    // 获得应用程序沙盒的tmp文件夹路径

    NSString *TmpPath= NSTemporaryDirectory();


    // 将文件写入到指定程序沙盒的指定文件夹中如Documents

    NSString *fileName=[homePath stringByAppendingPathComponent:@"Documents"];

    NSString *content=@"a";

    NSData *contentData=[content dataUsingEncoding:NSUTF8StringEncoding];


//此处只能写入基本类型的东西

    if ([contentData writeToFile:fileName atomically:YES]) {

        NSLog(@"写入成功");

    }

1 0
原创粉丝点击