pragma mark - 沙盒保存文件
+ (void)createDocumentFileName:(NSString *)fileName content:(NSDictionary *)contentDic
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *directory = [[NSString alloc]initWithFormat:@"%@/%@",documentsDirectory,fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
// 創(chuàng)建目錄
if (![fileManager fileExistsAtPath:directory])
{
[fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *filePath = [directory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
NSLog(@"filePath %@",filePath);
//寫文件
[contentDic writeToFile:filePath atomically:YES];
}
+ (NSDictionary *)getDocumentFileName:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *directory = [[NSString alloc]initWithFormat:@"%@/%@",documentsDirectory,fileName];
NSString *filePath = [directory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSLog(@"resultdic.....%@",resultDic);
return resultDic;
}
+ (void)deleteDocumentFileName:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *directory = [[NSString alloc]initWithFormat:@"%@/%@",documentsDirectory,fileName];
NSString *filePath = [directory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:filePath error:nil];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者