// Nsdata complies with the nscopying nscoding protocol. It provides object-oriented array storage for byte // applicable and read/write files, while a buffer zone is required for file read/write, nsdate provides such a cache zone // defines a char-type string const char * string = "Hi there, this is a C string"; // creates a buffer zone, add the string to nsdata * Data = [nsdata datawithbytes: String Length: strlen (string) + 1]; // output nslog (@ "data is % @", data ); nslog (@ "% lu bytes string is '% S'", [Data Length], [data bytes]); // defines a string, save a path nsstring * Path = @ "/tmp/ver.txt"; // Save the string of the saved path to another file. encoding is encoded [path writetofile: @ "/tmp/string.txt" atomically: Yes encoding: nsasciistringencoding error: Nil]; // Add an array and add several strings nsarray * phrase; phrase = [nsarray arraywithobjects: @ "I", @ "good", @ "seem", @ "to", nil]; // write the Array (the string path defined above) [Phrase writetofile: path atomically: Yes]; // print nslog (@ "% @", phrase ); // create a file manager/* nsfilemanager can be used to query single dictionary directories, create, rename, delete directories, and obtain/set file attributes */nsfilemanager * FM; fm = [nsfilemanager defaultmanager]; // create a buffer and use the nsfilemanager object to obtain the content in the file. That is, you can modify the nsdata * filedata; filedata = [FM contentsatpath: @ "/tmp/ver.txt"]; // print nslog (@ "file data is % @", filedata); // judge the nsdata object if (filedata) {nslog (@ "File Read success");} else {nslog (@ "File Read failed") ;}// defines a Boolean object bool ifsucess; // In objective-C, the correct is yes. The error is no ifsucess = no; // obtain the content of the file obtained from the above filedata object through the nsfilemanager object, create a new path and store ifsucess = [FM createfileatpath: @ "/tmp/test4.txt" Contents: filedata attributes: Nil]; // judge the Boolean object if (ifsucess) {nslog (@ "Create File sucess");} else {nslog (@ "Create File failed ");}