沙盒中存取删数据

2016-05-30  本文已影响74人  幻想no现实

#pragma mark -存储数据

-(void)SaveString:(NSString*)UrlStr

{

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

NSArray*data =@[UrlStr];

NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

[datawriteToFile:filepathatomically:YES];

}

读取数据

- (NSArray*)readData {

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

// 3.文件路径

NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

// 4.读取数据

NSArray*data = [NSArrayarrayWithContentsOfFile:filepath];

returndata;

}

删除数据

NSString *home = NSHomeDirectory();

// 2.document路径

NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];

NSFileManager * fileManager = [[NSFileManager alloc]init];

[fileManager removeItemAtPath:docPath error:nil];

上一篇下一篇

猜你喜欢

热点阅读