2011-12-16 16 views

回答

27

可能嗎? - 是

是否建議? - 除非它是一個非常大的文件,爲什麼不呢?

怎麼樣? - NSString - stringWithContentsOfFile:encoding:error:已經有一種方法可以幫您完成。

請參見下面的代碼片段:

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

不要忘了之後檢查錯誤。並確保將您的HTML文件保存爲UTF8。 – Ahti 2011-12-16 20:53:14

相關問題