ios高階課之 資料處理之檔案讀寫1

2021-07-11 11:13:26 字數 2781 閱讀 1447

今天剛進入學習ios高階課,第一節課講的是資料處理之檔案讀寫。

以下是自己整理的一些筆記

首先學了沙盒機制,沙盒是一種安全體系,它規定應用程式只能在為該應用程式建立的資料夾(沙盒)內訪問檔案,不可以去訪問其他沙盒的內容(ios8已經部分開發訪問);同時,所有的非**檔案都儲存在這個地方,如聲音、、屬性列表(plist)、sqlite資料庫和文字檔案等等。

沙盒的特點:

1.每個應用程式的活動範圍都限定在自己的沙盒內;

2.不能隨意跨越自己的沙盒去訪問別的應用的沙盒中的內容

3.應用程式向外請求或接收資料都要經過授權

沙盒目錄下有3個資料夾documents、library(裡面有caches和preferences目錄)、tmp。

documents是用來儲存應用執行時生成的需要持久化的資料;

library是儲存程式的預設設定和其他狀態資訊;

caches是存放快取檔案的,這個目錄裡的檔案不會在程式退出時刪除, 一般放體積較大,不是很重要的資源。

preferences是儲存應用的偏好設定,ios的settings應用匯在這個目錄中查詢應用的設定資訊。

**注意:不可以直接建立偏好設定檔案,應該用nsuserdefaults類來獲取和設定應用的偏好。**

tmp是儲存應用執行的時候所需要的臨時資料,使用過後再將該目錄中的檔案刪除。應用沒有執行的時候,系統也可能清除該目錄下的檔案。iphone重啟,會刪除該目錄下的檔案。

//獲取documents資料夾的路徑

nsstring *documentspath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0];

nslog(@"documentspath___%@", documentspath);

//獲取tmp資料夾路徑

nsstring *tmppath = nstemporarydirectory();

nslog(@"tmppath____%@", tmppath);

//獲取library/caches資料夾路徑

nsstring *cachespath = [nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes) objectatindex:0];

nslog(@"cachespath____%@", cachespath);

//建立path資料夾

[filemanager createdirectoryatpath:path withintermediatedirectories:yes attributes:nil error:nil];

nslog(@"path____%@", path);

//建立test.txt

//建立testdirectory

[filemanager createdirectoryatpath:[testdirpath stringbydeletinglastpathcomponent] withintermediatedirectories:yes attributes:nil error:nil];

//複製test.txt

[filemanager copyitematpath:testpath topath:testdirpath error:nil];

nslog(@"testdirpath____%@", testdirpath);

//第二種方法,個人感覺更加方便與快捷

//直接建立到底層檔案,不用乙個乙個區建立

nslog(@"tmppath___%@", tmppath);

上面是一些練習,簡單的獲取沙盒的資料夾路徑與建立檔案、資料夾、檔案的複製。

海量資料處理 高階程式設計師之海量資料處理

何謂海量資料處理?所謂海量資料處理,無非就是基於海量資料上的儲存 處理 操作。何謂海量,就是資料量太大,所以導致要麼是無法在較短時間內迅速解決,要麼是資料太大,導致無法一次性裝入記憶體。那解決辦法呢?針對時間,我們可以採用巧妙的演算法搭配合適的資料結構,如bloom filter hash bit ...

Python之資料處理

靠別人不如靠自己,學學學學學學學學!原資料 需求 coding utf 8 txtfile aminer1.txt newtxtfile open new txtfile,w with open txtfile,r as file to read lines file to read.readlin...

python之資料處理

檔案資料讀寫的基本操作 import this 本地檔案的界定 指向乙個本地儲存的檔案,是乙個連線或者乙個對映 path1 c users 11786 desktop test.txt 正斜線兩個或者反斜線乙個來用於資料路徑的表達 再或者用r 寫在檔案路徑外面 推薦第三種 path2 c users...