iOS在文件末尾写入内容
来源:互联网 发布:航信数据维护 编辑:程序博客网 时间:2024/05/29 21:16
-(NSString*)infoFilePath
{
NSArray *Paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES );
NSString *MyDocpath=[Paths objectAtIndex:0];
NSString *filename=[MyDocpathstringByAppendingPathComponent:[NSStringstringWithFormat:@"infoFile"]];
return filename;
}
-(NSString *)currentTime{
NSDate *currentDate = [NSDatedate];
NSDateFormatter *dateformatter=[[NSDateFormatteralloc] init];
[dateformattersetDateFormat:@"YYYY-MM-dd mm:ss"];
NSString *currentString=[dateformatter stringFromDate:currentDate];
return currentString;
}
-(void)allWriteToFileWithLocalMac:(NSString *)localMac andRemoteMac:(NSString *)remoteMac andLength:(int)length{
NSData *buffer;
if (![[NSFileManagerdefaultManager] fileExistsAtPath:[selfinfoFilePath]]) {
NSLog(@"%@",@"文件不存在");
NSString *s = [NSStringstringWithFormat:@"开始了:\r"];
[s writeToFile:[selfinfoFilePath]atomically:YESencoding:NSUTF8StringEncodingerror:nil];
}
NSString *filePath = [selfinfoFilePath];
NSFileHandle *outFile = [NSFileHandlefileHandleForWritingAtPath:filePath];
if(outFile == nil)
{
NSLog(@"Open of file for writing failed");
}
//找到并定位到outFile的末尾位置(在此后追加文件)
[outFileseekToEndOfFile];
//读取inFile并且将其内容写到outFile中
NSString *bs = [NSStringstringWithFormat:@"发送数据时间:%@--localMac:%@--remoteMac:%@--length:%d \n",[selfcurrentTime],localMac,remoteMac,length];
buffer = [bs dataUsingEncoding:NSUTF8StringEncoding];
[outFilewriteData:buffer];
//关闭读写文件
[outFilecloseFile];
}
//测试写入文件
[selfallWriteToFileWithLocalMac:LocalMac andRemoteMac:RemoteMac andLength:(int)[[NSDatadataWithBytes:local_onoff_msg length:128] length]];
- iOS在文件末尾写入内容
- java写入文件(文件内容末尾追加)
- java写入文件(文件内容末尾追加)
- java写入文件(文件内容末尾追加)
- 读取()txt文件中的内容与向txt文件中写入内容(覆盖重写与在末尾续写+FileOutputStream与FileWriter)
- ObjectOutputStream在文件末尾多次追加写入对象的解决方案
- 在linux下批量向文件末尾添加内容
- java写入文件(文件末尾追加)
- 追加内容到文件末尾
- 追加内容到文件末尾
- 向文件末尾添加内容
- MFC C++ CStdioFile类写入文件 在文件末尾追加数据
- 如何在文件末尾写入新数据(2011-12-23 15:49:50)
- 以app模式向文本文件末尾写入内容
- 读取写入文件内容
- 文件定位写入内容
- qt写入文件内容
- 在文件指定位置读取和写入内容RandomAccessFile
- 黑马程序员—C语言的指针
- echo命令
- 求逆序对模板题(完善模板:树状数组或归并排序)
- 独立和自由——不必心有纠缠
- Leetcode70: Binary Tree Postorder Traversal
- iOS在文件末尾写入内容
- LintCode--最大子数组差
- 多线程-NSOperation
- 关于C++中的类型转换操作符
- android官方培训教程
- UVA 156 Ananagrams
- hihoCoder 1236 Scores(2015 北京网赛 J)
- Peeking Iterator
- CoreText<1>