『IOS』iOS的四种方法读取文件内容
来源:互联网 发布:小米3w支持什么网络 编辑:程序博客网 时间:2024/05/02 12:36
原文地址:iOS的四种方法读取文件内容
#import <foundation foundation.h> int main(int argc, const char * argv[]){ @autoreleasepool { //第一种方法: NSFileManager实例方法读取数据 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); NSString* thepath = [paths lastObject]; thepath = [thepath stringByAppendingPathComponent:@"fd_list.txt"]; NSLog(@"桌面目录:%@", thepath); NSFileManager* fm = [NSFileManager defaultManager]; NSData* data = [[NSData alloc] init]; data = [fm contentsAtPath:thepath]; NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); //第二种方法: NSData类方法读取数据 data = [NSData dataWithContentsOfFile:thepath]; NSLog(@"NSData类方法读取的内容是:%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); //第三种方法: NSString类方法读取内容 NSString* content = [NSString stringWithContentsOfFile:thepath encoding:NSUTF8StringEncoding error:nil]; NSLog(@"NSString类方法读取的内容是:\n%@",content); //第四种方法: NSFileHandle实例方法读取内容 NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:thepath]; data = [fh readDataToEndOfFile]; NSLog(@"NSFileHandle实例读取的内容是:\n%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); } return 0;}
0 0
- 『IOS』iOS的四种方法读取文件内容
- iOS四种方法读取文件内容
- iOS的四种方法读取文件内容
- iOS的四种方法读取文件内容
- iOS的四种方法读取文件内容
- ios中读取plist文件内容的方法
- Python四种逐行读取文件内容的方法
- IOS中plist文件内容的读取
- iOS 文件预览的四种方法
- iOS 文件预览的四种方法
- iOS 读取plist文件内容
- iOS : 通过路径读取文件的几种方法
- ios 读取文件有两种方法
- iOS文件读取方法 节选
- iOS从plist文件里面读取内容
- 读取文件内容的方法
- Java文件读取的四种方法
- IOS读取本地文件内容
- 通讯录
- NSNumber
- Java线程(八):锁对象Lock-同步问题更完美的处理方式
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem
- 黑马程序员----线程池的通俗理解!面试时候高频率问题
- 『IOS』iOS的四种方法读取文件内容
- python numpy 中函数记录
- Java进阶之欧拉工程 第十二篇【有大量约数的三角数】
- 工作流问题总结(1)
- XDOJ1010--素数环问题
- poj 3009 dfs + 恢复
- 简单的tableView
- 2014.08.15 总结
- 从尾到头输出链表