File System Basic
About the iOS File System
1. During installation of a new app, the installer code creates a home directory for the app, places the app in that directory, and creates several other key directories. These directories constitute the app’s primary view of the file system.
2. 通常app被限制只能在sandbox中创建或访问文件。有一个例外是,当app使用public system接口时
3. When an app is installed on a device, iTunes creates a home directory for the app.当一个app被安装到设备上时,iTunes创建了一个home directory。
4. Application bundle directory (binary, .storyboards, .jpgs, etc.). This directory is NOT writeable.
Documents directory. This is where you store permanent data created by the user.
Caches directory. Store temporary files here (this is not backed up by iTunes).
Other directories (check out NSSearchPathDirectory in the documentation).
Accessing Files and Directories
1.获取sandbox中目录地址
- (NSString *)stringByAppendingPathComponent:(NSString *)component;
- (NSString *)stringByDeletingLastPathComponent;
- (NSArray *)URLsForDirectory:(NSSearchPathDirectory)directory // see below
inDomains:(NSSearchPathDomainMask)domainMask; //NSUserDomainMask
NSSearchPathDirectory {
}NSDocumentsDirectory, NSCachesDirectory, NSAutosavedInformationDirectory
2. Provides utility operations (reading and writing is done via NSData, et. al.).
Check to see if files exist; create and enumerate directories; move, copy, delete files; etc. Just alloc/init an instance and start performing operations.
Thread safe (as long as a given instance is only ever used in one thread).