IOS NSFileManager file operations, iosnsfilemanager
Reference: http://blog.csdn.net/xyz_lmn/article/details/8968213 thanks to these pioneers
Common file operations:
// Obtain the sandbox root path NSString * dirHome = NSHomeDirectory (); NSLog (@ "% @", dirHome ); // obtain the Documents directory path NSArray * path = NSSearchPathForDirectoriesInDomains (NSDocumentationDirectory, NSUserDomainMask, YES); NSString * documentsDirectory = [path objectAtIndex: 0]; NSLog (@ "% @", documentsDirectory); // obtain the Library directory path = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, YES); NSString * libraryD Irectory = [path objectAtIndex: 0]; NSLog (@ "% @", libraryDirectory); // obtain the caches directory path = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES ); NSString * caches = [path objectAtIndex: 0]; NSLog (@ "% @", caches); // obtain the Tmp directory path NSString * tmpDirectory = NSTemporaryDirectory (); NSLog (@ "% @", tmpDirectory ); // create a folder // 1 obtain the file path // 2 create a file manager // 3 create a file path in the directory using the File Manager = NSSearchPathForDirector IesInDomains (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory failed: @ "test"]; NSFileManager * fm = [NSFileManager defamanager manager]; BOOL res = [fm createDirectoryAtPath: documentsDirectory withIntermediateDirectories: YES attributes: nil error: nil]; if (! Res) {NSLog (@ "folder created successfully");} else {NSLog (@ "Folder creation failed");} // create a file (same as the Folder creation) path = catalog (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "text"]; documentsDirectory = [documentsDirectory catalog metadata: @ "123.txt"]; fm = [NSFileManager defaultManager]; res = [fm createDirectoryAtPath: documentsDirectory withIntermediateDirectories: YES attributes: nil error: nil]; if (res) {NSLog (@ "folder created successfully");} else {NSLog (@ "folder created failed");} // write data to the file path = NSSearchPathForDirectoriesInDomains (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "text"]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "123.txt"]; NSString * content = @ "file written content"; res = [content writeToFile: documentsDirectory atomically: YES encoding: NSUTF8StringEncoding error: nil]; if (res) {NSLog (@ "folder created successfully");} else {NSLog (@ "folder created failed");} // read file data path = NSSearchPathForDirectoriesInDomains (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "text"]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "123.txt"]; content = [NSString stringWithContentsOfFile: documentsDirectory encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "File Read succeeded: % @", content ); // file attributes path = require (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "text"]; documentsDirectory = [documentsDirectory attributes: @ "123.txt"]; fm = [NSFileManager defaultManager]; NSDictionary * fileAttributes = [fm attributesOfItemAtPath: documentsDirectory error: nil]; NSArray * keys; id key, value; keys = [fileAttributes allKeys]; int count = [keys count]; for (int I = 0; I <count; I ++) {key = [keys objectAtIndex: i]; value = [fileAttributes objectForKey: key]; NSLog (@ "Key: % @ for value: % @", key, value );} // delete file path = NSSearchPathForDirectoriesInDomains (NSDocumentationDirectory, NSUserDomainMask, YES); documentsDirectory = [path objectAtIndex: 0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "text"]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent: @ "123.txt"]; fm = [NSFileManager defaultManager]; res = [fm removeItemAtPath: documentsDirectory error: nil]; if (res) {NSLog (@ "File deleted successfully") ;}{ NSLog (@ "File deleted failed ");}
In iOS development, the binary stream of documents such as word, excel, and pdf is stored locally (iPhone or iPad ).
Can't Data be directly written into the disk? The format of the file you received is saved as follows:
Ios and iso files
It should be an ISO file, which may be a mistake. Generally, all downloaded files are ISO image files, which are used for CD burning or installation and extraction.