iphone - iOS - 如何将 html 资源文件的全部内容读入 NSString *?

标签 iphone ios

我想将我的html 资源文件的内容放入一个NSString 对象中。这样做是否可行且可取?怎么做到的?

最佳答案

可能吗? - 是的

可取吗? - 除非它是一个非常大的文件,为什么不呢?

如何? - NSString - stringWithContentsOfFile:encoding:error: 中已经有一个方法可以为您完成。

请看下面的片段:

NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: @"foo" ofType: @"html"];
NSString *res = [NSString stringWithContentsOfFile: path encoding:NSUTF8StringEncoding error: &error];

关于iphone - iOS - 如何将 html 资源文件的全部内容读入 NSString *?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8539693/

相关文章:

iphone - NSThread detachNewThreadSelector 锁定主线程

ios - 键盘在 ios7 (Xcode 6) 中无法正常工作

ios - RKManagedObjectRequestOperation objc_msgSend 期间 RestKit 崩溃

ios - react-native-intercom 抛出神秘错误 - 体系结构 x86_64 的 undefined symbol

iphone - 使用 NSUserDefaults 保存 NSMutableArray

ios - 使用 dispatch_once 启动定位服务

iPhone notification_post 通知

ios - UIPickerView 文本比例不够

iphone - objective-c : Do I have to retype all the code everytime?

iphone - 要在 ios 中显示 map ,我们应该使用 ArcGIS Apis 还是 Google Map API?