赞
踩
- -(void)CWriteFile:(NSString*)logStr isLogTime:(BOOL)_isLogTime
- {
-
- /获取路径
- NSString *sandboxPath = NSHomeDirectory();
- NSString *documentPath = [sandboxPath stringByAppendingPathComponent:@"Documents"];//将Documents添加到sandbox路径上//
- NSString *FileName=[documentPath stringByAppendingPathComponent:@"log.txt"];//fileName就是保存文件的文件名
- 获取当前时间
- if(_isLogTime)
- {
- NSDate * nowdate=[NSDate date];
- NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
- [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
- NSString * locationString=[dateformatter stringFromDate:nowdate];
- logStr = [NSString stringWithFormat:@"%@:%@",locationString,logStr];
- [dateformatter release];
- }
- 写入并关闭
- FILE *fp = NULL;
- fp = fopen(FileName.cString, "a+" );
- if( fp == NULL )
- {
- return;
- }
- fprintf( fp, logStr.cString);
- fclose( fp);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。