OC學習 檔案讀寫

2021-07-04 12:40:20 字數 1310 閱讀 3964

//拿到tmp路徑

nsstring *tmppath = nstemporarydirectory();

nslog(@"%@",tmppath);

//獲取nsfilemanager單例類,用於檔案操作

nsfilemanager *filemanager = [nsfilemanager defaultmanager];

//用nsfilemanager單例類判斷是否為資料夾是否存在

// bool i***ist = [filemanager fileexistsatpath:imgs];

// nslog(@"%d",i***ist);

//找到程式應用的跟路徑

nsstring *rootpath = nshomedirectory();

nslog(@"%@",rootpath);

//在跟路徑後面新增/documents就是documents路徑

//函式獲取document路徑。

dicumentspath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0];

// 拿到library路徑

//錯誤路徑

// nslog(@"%@",library);

nslog(@"%d",[filemanager fileexistsatpath:library]);

//函式獲取library路徑

library = [nssearchpathfordirectoriesindomains(nslibrarydirectory, nsuserdomainmask, yes) objectatindex:0];

nslog(@"%@",library);

nserror *error;

bool issuccess = [filemanager createdirectoryatpath:mypath withintermediatedirectories:yes attributes:nil error:&error];

nslog(@"%d",issuccess);

nsarray *imagearray = @[@"",@"",@"",@"",@"nil"];

int i = 0;

while (i < imagearray.count) else else

}nslog(@"%@",nshomedirectory());

}i++;

}

OC學習 檔案操作

oc中檔案的操作可以分為兩類 1 檔案本省的操作 建立 刪除 移動 拷貝等 2 檔案內容的操作 讀 寫等 讀 磁碟 記憶體 寫 記憶體 磁碟 要想學會oc中的檔案操作,我們就要學會兩個類 nsfilemanager 檔案管理類 nsfilehandle 檔案控制代碼類 一 nsfilemanager...

Python學習(檔案讀寫)

一 用os.makedirs 建立新資料夾 在桌面上建立乙個名稱為1的資料夾。import os os.makedirs c users king desktop 1 二 檢視檔案大小和資料夾內容 1.os.path.getsize path 返回path 引數中檔案的位元組數。import os ...

Python學習 檔案讀寫

資料的讀取 對檔案數的讀取是用read 方法,read 方法將返回檔案中的所有內容 eg content f.read print content f.close 注 記得每次用完檔案後,都要關閉檔案。否則檔案就會一直被占用,不能被其他程序使用 也可以使用with open as f 在操作後自動關...