日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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://www.dlmjj.cn/article/ccssgee.html