iOS項目運行有四個文件目錄,如圖所示:
Paste_Image.png
1.Documents 目錄:存儲用戶數據或其它應該定期備份的信息.
2.Library 目錄:目錄下有兩個子目錄,.Caches 目錄:用于存放應用程序專用的支持文件,保存應用程序再次啟動過程中需要的信息.PreferencesPreferences 目錄:包含應用程序的偏好設置文件。不應該直接創建偏好設置文件,應該通過NSUserDefaults類來取得和設置應用程序的偏好.
3.tmp 目錄:目錄用于存放臨時文件,保存應用程序再次啟動過程中不需要的信息.
4.AppName.app 目錄:應用程序的程序包目錄,包含應用程序的本身。由于應用程序必須經過簽名,所以您在運行時不能對這個目錄中的內容進行修改,否則可能會使應用程序無法啟動.資源圖片文件都在這個目錄下面.
路徑獲取代碼:
<pre><code>`
let documentPath:String = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0]
print("Document路徑----(documentPath)")
let libraryPath:String = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.libraryDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0]
print("library路徑----\(libraryPath)")
let cachePath:String = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0]
print("Cache路徑----\(cachePath)")
let preferPath:String = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.preferencePanesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0]
print("Prefer路徑----\(preferPath)")
let homeDir:String = NSHomeDirectory()
print("沙盒地址---\(homeDir)")
let imagePath = Bundle.main.path(forResource: "sale", ofType: "png")!
print("FlyElephnt-圖片路徑----\(imagePath)")
let bundlePath = Bundle.main.bundleURL.path
print("FlyElephnt-App資源文件路徑--\(bundlePath)")
let testDataPath = Bundle.main.bundleURL.appendingPathComponent("FlyElephant").path
print("壓縮文件的路徑---\(testDataPath)")`</code></pre>