iOS檔案讀寫

2021-07-23 14:48:43 字數 442 閱讀 3108

- (void)viewdidload 

/*從指定的路徑下讀取檔案的資料

原則:寫入什麼型別,需要用該型別接收

*/nsarray *arrayfromfile = [nsarray arraywithcontentsoffile:filepath];

//需求二:把字典資料寫入檔案中

nsdictionary *dic = @;

[dic writetofile:dicfilepath atomically:yes];

//讀取字典資料

nsdictionary *dicfromfile = [nsdictionary dictionarywithcontentsoffile:dicfilepath];

nslog(@"字典資料:%@", dicfromfile);

}

ios檔案讀寫

在這個目錄下面,有四個目錄需要了解 documents 這是用來儲存使用者檔案的首選目錄。library 這個目錄作為preference目錄的父目錄而單獨存在 tmp 訪問檔案 nsfilemanager 是用來訪問檔案系統的主要類 nsfilemanager filemanager nsfile...

ios 檔案讀寫

分別是 既然要進行檔案讀寫,那我們就需要得到檔案目錄路徑,得到路徑的方法有以下幾種 1 先獲取根目錄,然後進行字串拼接 例如 獲取程式根目錄 nsstring homepath nshomedirectory 獲取根目錄下的documents目錄 或者。這個與上面方法的區別在於要不要加 2 一般對於...

ios中讀寫檔案

在ios的開發中,經常遇到要讀寫檔案的情況,例如處理 採集資訊等,那麼在ios中對檔案的讀寫有兩種方式 1 使用nsdata 來將整個資料讀取到記憶體中 將檔案寫到檔案中 使用這種方式比較適合針對小檔案的讀寫,可以全部的讀到記憶體中處理,比如說全域性性的配置檔案等。2 使用c的api來讀取 在ios...