-(void)createFiel{
//創(chuàng)建文件管理器
NSFileManager *fileManager = [NSFileManager defaultManager];
//獲取document路徑,括號(hào)中屬性為當(dāng)前應(yīng)用程序獨(dú)享
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, ? ? ?NSUserDomainMask, YES);
NSString *documentDirectory = [directoryPaths objectAtIndex:0];
//定義記錄文件全名以及路徑的字符串filePath
filePath = [documentDirectory stringByAppendingPathComponent:@"history.txt"];
//查找文件茬暇,如果不存在近忙,就創(chuàng)建一個(gè)文件
if (![fileManager fileExistsAtPath:filePath]) {
[fileManager createFileAtPath:filePath contents:nil attributes:nil];
}
}
//讀寫本地歷史記錄 ?isgetData == yes 獲取數(shù)據(jù), ?寫入數(shù)據(jù)
-(void)getHistoryData:(BOOL)isGetData {
if (isGetData == NO) {
// ? ? ? ?NSString *str = [NSString stringWithContentsOfFile:filePath usedEncoding:nil error:nil];
NSString *historyStr = [ historyArry componentsJoinedByString:@","];
[historyStr writeToFile:filePath atomically:YES
encoding:NSUTF8StringEncoding error:nil];
//通過將writeToFile:atomically:encoding:error:方法發(fā)送給字符串對象完成字符串存儲(chǔ)到文件內(nèi)的功能
}else{
NSString *str = [NSString stringWithContentsOfFile:filePath usedEncoding:nil error:nil];
//[historyArry removeAllObjects];
//[historyArry addObject:@""];
if(str.length!=0){
//[historyArry addObjectsFromArray:[ str componentsSeparatedByString:@","]];
}
NSLog(@"%@",str);
}
}