• iOS开发学习笔记(OC语言)——文件基本操作


    文件基本操作

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [paths firstObject];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    //创建文件夹
    NSString *dataPath = [cachePath stringByAppendingPathComponent:@"FirstData"];
    NSError *createError;
    [fileManager createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:&createError];
    
    //创建文件
    NSString *listDataPath = [dataPath stringByAppendingPathComponent:@"list"];
    NSData *listData = [@"abc" dataUsingEncoding:NSUTF8StringEncoding];
    [fileManager createFileAtPath:listDataPath contents:listData attributes:nil];
    
    //查询文件
    BOOL fileExist = [fileManager fileExistsAtPath:listDataPath];
    
    if (fileExist) {
        //文件追加内容
        NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:listDataPath];
        [fileHandle seekToEndOfFile];
        [fileHandle writeData:[@"\ndef" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle synchronizeFile];
        [fileHandle closeFile];
    }
    
  • 相关阅读:
    python之函数用法id(),了解即可
    python之函数用法locals()
    python之函数用法vars()
    python之函数用法execfile()
    python之函数用法isinstance()
    python之函数用法any()
    python之函数用法iter()
    python之函数用法file()
    python之函数用法bin()
    python之函数用法basestring
  • 原文地址:https://www.cnblogs.com/lurenjiashuo/p/15934438.html
Copyright © 2020-2023  润新知