日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
創(chuàng)新互聯(lián)IOS教程:iOS文件處理

iOS文件處理


簡介

文件處理不能直觀的通過應用程序來解釋,我們可以從以下實例來了解IOS的文件處理。

從網站建設到定制行業(yè)解決方案,為提供網站設計、網站建設服務體系,各種行業(yè)企業(yè)客戶提供網站建設解決方案,助力業(yè)務快速發(fā)展。創(chuàng)新互聯(lián)建站將不斷加快創(chuàng)新步伐,提供優(yōu)質的建站服務。

IOS中對文件的操作. 因為應用是在沙箱(sandbox)中的,在文件讀寫權限上受到限制,只能在幾個目錄下讀寫文件。

文件處理中使用的方法

下面列出了用于訪問和操作文件的方法的列表。

以下實例你必須替換FilePath1、FilePath和FilePath字符串為完整的文件路徑,以獲得所需的操作。

檢查文件是否存在

   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");
    }    

比較兩個文件的內容

   if ([fileManager contentsEqualAtPath:@"FilePath1" andPath:@" FilePath2"]) {
      NSLog(@"Same content");
   }

檢查是否可寫、可讀、可執(zhí)行文件

  if ([fileManager isWritableFileAtPath:@"FilePath"]) {
      NSLog(@"isWritable");
   }
   if ([fileManager isReadableFileAtPath:@"FilePath"]) {
      NSLog(@"isReadable");
   }
   if ( [fileManager isExecutableFileAtPath:@"FilePath"]){
      NSLog(@"is Executable");
   }

移動文件

   if([fileManager moveItemAtPath:@"FilePath1" 
   toPath:@"FilePath2" error:NULL]){
      NSLog(@"Moved successfully");
   }

復制文件

   if ([fileManager copyItemAtPath:@"FilePath1" 
   toPath:@"FilePath2"  error:NULL]) {
      NSLog(@"Copied successfully");
   }

刪除文件

 if ([fileManager removeItemAtPath:@"FilePath" error:NULL]) {
      NSLog(@"Removed successfully");
   }
 

讀取文件

 NSData *data = [fileManager contentsAtPath:@"Path"];
 

寫入文件

  [fileManager createFileAtPath:@"" contents:data attributes:nil];

本文名稱:創(chuàng)新互聯(lián)IOS教程:iOS文件處理
標題網址:http://m.5511xx.com/article/ccssgee.html