NSFileManager can:
Create a new file
Read from an exiting file
Write data to file
Rename a file
Remove (delete a file)
Test for the existence of a file
Determine the size of a file as well as other attributes
Make a copy of a file
Test two files to see whether their contents are equal
這些操作都可以被在directories下執(zhí)行。例如你創(chuàng)建一個(gè)目錄,讀出其中元素或者刪除。另一個(gè)特色是link files。也就是,一個(gè)相同的文件存在在兩個(gè)不同的名字下,或許甚至是不同的目錄下。
為了打開(kāi)一個(gè)文件并執(zhí)行多次讀寫(xiě)操作,你用NSFileHandle提供的方法。主要:
Open a file or reading, writing , or updating (reading and writing)
Seek to a specified position within a file
Read or write a specified number of bytes from and to a file.
這個(gè)類提供的方法也可以被應(yīng)用在Device 或者 socket上。
管理文件和目錄:NSFileManager
一個(gè)文件或者目錄被通過(guò)pathname 唯一的定義給NSFileManager。 一個(gè)pathname就是一個(gè)NSString類型對(duì)象能被相關(guān)聯(lián)或者是全部的pathname。
一
個(gè)相關(guān)聯(lián)的pathname是關(guān)聯(lián)到當(dāng)前目錄的那個(gè)pathname 。 所以文件名字copy1.m
將意味著這個(gè)文件在當(dāng)前的目錄。“/”(Slash) 實(shí)際上是根目錄。/users/somone 是一個(gè)pathname 指定3個(gè)目錄 /
根目錄,users目錄和someone目錄。
~被用來(lái)縮寫(xiě)一個(gè)用戶的主目錄比如~linda = /users / linda。 在UNIX類型的pathname里面 “ ." 就是當(dāng)前目錄". . "就是父目錄(上一級(jí))
NSData:
用這個(gè)類來(lái)處理文件的時(shí)候,你常常需要讀出一個(gè)臨時(shí)區(qū)域中的變量,通常叫做buffer(緩沖區(qū))。NSData類提供一個(gè)簡(jiǎn)單的方式建立緩沖區(qū),讀出里面文件的內(nèi)容,或者寫(xiě)一個(gè)buffer中的內(nèi)容到一個(gè)文件。
你可以定義可變的或者不可變的存儲(chǔ)空間。