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下執行。例如你創建一個目錄,讀出其中元素或者刪除。另一個特色是link files。也就是,一個相同的文件存在在兩個不同的名字下,或許甚至是不同的目錄下。
為了打開一個文件并執行多次讀寫操作,你用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.
這個類提供的方法也可以被應用在Device 或者 socket上。
管理文件和目錄:NSFileManager
一個文件或者目錄被通過pathname 唯一的定義給NSFileManager。 一個pathname就是一個NSString類型對象能被相關聯或者是全部的pathname。
一
個相關聯的pathname是關聯到當前目錄的那個pathname 。 所以文件名字copy1.m
將意味著這個文件在當前的目錄。“/”(Slash) 實際上是根目錄。/users/somone 是一個pathname 指定3個目錄 /
根目錄,users目錄和someone目錄。
~被用來縮寫一個用戶的主目錄比如~linda = /users / linda。 在UNIX類型的pathname里面 “ ." 就是當前目錄". . "就是父目錄(上一級)
NSData:
用這個類來處理文件的時候,你常常需要讀出一個臨時區域中的變量,通常叫做buffer(緩沖區)。NSData類提供一個簡單的方式建立緩沖區,讀出里面文件的內容,或者寫一個buffer中的內容到一個文件。
你可以定義可變的或者不可變的存儲空間。