美文网首页
iOS文件管理

iOS文件管理

作者: Mr_Lin_ | 来源:发表于2021-01-25 09:15 被阅读0次

- (void)_getSandBoxPath {

    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

    NSString*cachesPath = [pathArray firstObject];

    NSFileManager *fileManger = [NSFileManager defaultManager];

    //创建文件夹

    NSString *dataPath = [cachesPath stringByAppendingPathComponent:@"HomeListData"];

    NSError *createError;

    [fileManger createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:&createError];

    //创建文件

    NSString *listDataPath = [dataPath stringByAppendingPathComponent:@"listData"];

    NSData *listData = [@"abc" dataUsingEncoding:NSUTF8StringEncoding];

    [fileManger createFileAtPath:listDataPath contents:listData attributes:nil];

    //查询文件

    __unused BOOL isExist = [fileManger fileExistsAtPath:listDataPath];

//    if (isExist) {

//        [fileManger removeItemAtPath:listDataPath error:nil];

//    }

    //更新文件

    NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:listDataPath];

    [fileHandle seekToEndOfFile];

    [fileHandle writeData:[@"def" dataUsingEncoding:NSUTF8StringEncoding] error:nil];

    [fileHandle synchronizeFile];

    [fileHandle closeFile];

}

相关文章

  • IOS文件管理

    iOS开发-文件管理(一) 一、iOS中的沙盒机制 iOS应用程序只能对自己创建的文件系统读取文件,这个独立、封闭...

  • iOS文件管理

    iOS开发-文件管理(一) 一、iOS中的沙盒机制 iOS应用程序只能对自己创建的文件系统读取文件,这个独立、封闭...

  • flutter iOS 混编步骤

    1.创建公共文件 2.创建iOS项目 3.创建flutter模块 iOS引入pod管理 在profile文件中添加...

  • gitsubmodule 管理子模块

    我们在进行RN混合开发的时候,想使ios、android的文件与RN的主文件进行分开管理,但是主文件要引用ios、...

  • iOS 文件管理

    一、iOS中的沙盒机制 iOS应用程序只能对自己创建的文件系统读取文件,这个独立、封闭、安全的空间,叫做沙盒。它一...

  • IOS文件管理

    文件操作 NSFileManager 1.NSFileManager 专门负责文件/文件夹的管理操作,包括创建/删...

  • iOS文件管理

    一、iOS中的沙盒机制 iOS应用程序只能对自己创建的文件系统读取文件,这个独立、封闭、安全的空间,叫做沙盒。它一...

  • iOS文件管理

    文件管理器 1、判断文件是否存在 2、获取文件或者文件夹的属性 3、获取文件夹中所有文件 浅度遍历 深遍历 4、创...

  • iOS文件管理

    NSFileManager和NSFilehandle类 NSFileManager NSFileManager类是...

  • iOS文件管理

    - (void)_getSandBoxPath { NSArray *pathArray = NSSearch...

网友评论

      本文标题:iOS文件管理

      本文链接:https://www.haomeiwen.com/subject/vugszktx.html