




- (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];
}
网友评论