IOS file management

IOS file management

IOS file management

IOS file management

IOS file management

IOS file management

– (void)_getSandBoxPath {

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

    NSString*cachesPath = [pathArray firstObject];

    NSFileManager *fileManger = [NSFileManager defaultManager];

//Create folder

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

    NSError *createError;

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

//Create file

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

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

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

//Query file

    __unused BOOL isExist = [fileManger fileExistsAtPath:listDataPath];

//    if (isExist) {

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

//    }

//Update file

    NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:listDataPath];

    [fileHandle seekToEndOfFile];

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

    [fileHandle synchronizeFile];

    [fileHandle closeFile];


Recommended Today

Game case | application evolution and practice of service mesh in happy games

author Chen Zhiwei, Tencent level 12 background expert engineer, is now responsible for the public background technology research and development and team management of happy game studio. Rich experience in micro service distributed architecture and game background operation and maintenance research and development. preface The background of happy game studio is a distributed micro service […]