IOS 讀取專案中的檔案方法

2022-09-06 19:48:11 字數 756 閱讀 5837

在專案中,經常需要讀取配置檔案,現在就來看看讀取plist配置檔案的**

//

讀取專案下的檔案路徑

nsbundle *bundle =[nsbundle mainbundle];

nsstring *plistpath = [bundle pathforresource:@"

filename

" oftype:@"

plist"];

//可轉換成url

nsurl *url =[nsurl fileurlwithpath:path];

//如nsxml就需要提供url位址

nsxmlparser *parser =[[nsxmlparser alloc] initwithcontentsofurl:url];

//換成nsdata

nsdata*data = [[nsdataalloc]initwithcontentsoffile:path];

//

可直接轉換成對應檔案格式

//當plist檔案為字典是可用以下方法

nsdictionary *dict =[[nsdictionary alloc]initwithcontentsoffile:plistpath];

//當plist檔案為陣列型別可以使用以下方法

nsarray *array = [[nsarray alloc] initwithcontentsoffile:plistpath];

獲取專案中的檔案方法

tomcat環境獲取檔案方法 string htmlfile request.getservletcontext getrealpath html zhantu.html 下面是我在jersey框架中開發的 springboot環境獲取resouces下的檔案方法 resourceutils.get...

讀取springboot專案中的檔案及路徑

比如讀取nopic.png 推薦使用 inputstream inputstream this.getclass getclassloader getresourceasstream static nopic.png 直接轉換成io流的格式 然後對流進行操作,注意用該方法路徑開頭不能帶 既是 sta...

讀取專案中的資源

有時會直接通過拉拽的方式,將檔案新增到專案中,這時一定要注意3點 destination 一定要勾選 不然只是一定引用 新增進來了 到時專案要是提交的時候 就會缺少檔案 added folders add to target 一定要勾選 今天碰到的問題是 給專案新增caf聲音檔案 結果 pewpew...