iOS file processing

Source: Internet
Author: User

Introduction to iOS file processing

File processing cannot be interpreted intuitively through the application, and we can learn about the file processing of iOS from the following examples.

Action on the file in iOS. Because the application is in the sandbox (sandbox), the file read and write permissions are restricted, only a few directories to read and write files.

Methods used in file processing

The list of methods used to access and manipulate files is listed below.

The following instance you must replace the FILEPATH1, filepath, and filepath strings for the full file path to get the desired action.

Check if the file exists

   Nsfilemanager *filemanager = [Nsfilemanager Defaultmanager];   Get documents directory   Nsarray *directorypaths = Nssearchpathfordirectoriesindomains   ( NSDocumentDirectory, Nsuserdomainmask, YES);   NSString *documentsdirectorypath = [directorypaths objectatindex:0];   if ([FileManager fileexistsatpath:@ ""]==yes) {        NSLog (@ "File exists");    }    

Compare the contents of two files

   if ([FileManager contentsequalatpath:@ "FilePath1" andpath:@ "FilePath2"]) {      NSLog (@ "Same content");   }

Check for writable, readable, executable files

  if ([FileManager iswritablefileatpath:@ "FilePath"]) {      NSLog (@ "iswritable");   }   if ([FileManager isreadablefileatpath:@ "FilePath"]) {      NSLog (@ "isreadable");   }   if ([FileManager isexecutablefileatpath:@ "FilePath"]) {      NSLog (@ "is executable");   }

Moving files

   if ([FileManager moveitematpath:@ "FilePath1"    topath:@ "FilePath2" Error:null]) {      NSLog (@ "Moved Successfully ");   }

Copying files

   if ([FileManager copyitematpath:@ "FilePath1"    topath:@ "FilePath2"  Error:null]) {      NSLog (@ "Copied Successfully ");   }

deleting files

if ([FileManager removeitematpath:@ "FilePath" Error:null]) {      NSLog (@ "removed successfully");   

Read file

Write file

  [FileManager createfileatpath:@ "" Contents:data Attributes:nil];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.