zoukankan      html  css  js  c++  java
  • iOS对于目录的操作

    原文地址:iOS对于目录的操作作者:angellixf
    iOS可操作目录有两种:Documents下与Caches下, 如图:
    [转载]iOS对于目录的操作 - 102212335 - 缘的博客

    [转载]iOS对于目录的操作 - 102212335 - 缘的博客

     
    1、创建目录createDirectoryAtPath:withIntermediateDirectories:attributes:error:

    NSFileManager * fileManager = nil;

    NSArray *paths = nil;

    NSString *documentsDirectory = nil;

    NSString * folerName = @"Photos";

    NSString * fileName = @"myphoto.png";

    NSString  * filePath = nil;

    UIImage *photoimage = nil;

    NSData * imageData = nil;

     

    //Documents:

     

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

     

    //Caches:

    paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

     

    documentsDirectory = [[paths objectAtIndex:0stringByAppendingPathComponent:folerName];

    fileManager = [[NSFileManager alloc]init];

    [fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:error];

     

     

     

     

     

    2、创建目录并在目录中存储对象createFileAtPath: contents: attributes

     

    filePath = [documentsDirectory stringByAppendingPathComponent:filename];

     

    if((![fileManager fileExistsAtPath: fullPathToFile])) 

         {

    photoimage = [[UIImage allocimageNamed:@"photo.png"];

    imageData = UIImagePNGRepresentation(photoimage);

    [fileManager createFileAtPath:filePath contents: imageData attributes:nil];

        }

    [photoimage release];

    [fileManager release];

     

     

    3、删除目录中指定文件

     

    NSString * filePath = [documentsDirectory stringByAppendingPathComponent: fileName];

    [filemanager removeItemAtPath: filePath error:NULL];
  • 相关阅读:
    gitlab 国内镜像安装
    docker 安装和启动redis
    jenkins 国内镜像更新地址
    docker 安装 jenkins
    docker 使用阿里云镜像加速
    '
    windows/linux 命令可以用符号连接执行
    思科访问控制列表优先级
    交换机泛洪
    虚拟机floppy0
  • 原文地址:https://www.cnblogs.com/xiaonanxia/p/2729239.html
Copyright © 2011-2022 走看看