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];
  • 相关阅读:
    WebGL-四之二
    WebGL-四之一
    mybatis中批量更新的问题
    nginx+tpmcat+redis实现session共享
    myeclipse快捷方式汇总
    StringBuffer的append方法比“+”高效
    《Thinking in Java》 And 《Effective Java》啃起来
    JAVA链表中迭代器的实现
    myeclipse从SVN检出项目报错
    C#中清空ListView中的数据
  • 原文地址:https://www.cnblogs.com/xiaonanxia/p/2729239.html
Copyright © 2011-2022 走看看