iOS中NSFileManager的簡單用法

2021-07-05 08:06:33 字數 1979 閱讀 2562

#import 

int main(int argc, const

char * argv)

// if ([fm isdeletablefileatpath:@"/"])

//獲取某一檔案的屬性

// nsstring *filepath = @"/users/huihui/desktop/1.png";

// nsdictionary *dict = [fm attributesofitematpath:filepath error:nil];

// nslog(@"%@",dict);

//獲取某一目錄下的內容

// nsstring *path2 = @"/users/huihui/desktop";

// nsarray *allarray = [fm subpathsatpath:path2];

// nsarray *subarrays = [fm contentsofdirectoryatpath:path2 error:nil];

// nslog(@"%@",subarrays);

// //建立目錄

// nsstring *createpath = @"/users/huihui/desktop/aaa";

// if( [fm createdirectoryatpath:createpath withintermediatedirectories:yes attributes:nil error:nil] )

// nslog(@"建立目錄成功!");

// else

// nslog(@"建立目錄不成功!");

// //建立檔案

// nsstring *content = @"曾經有乙份愛情,放在我面前,我沒有珍惜,直到失去後我才後悔莫及,如果上天能再給我一次機會,我願意對那個女孩說三個字」我愛你「,如果要為這份愛加乙個期限,我希望是一萬年";

nsstring *filepath = @"/users/huihui/desktop/aaa/love.txt";

// nsdata *contentdata = [content datausingencoding:nsutf8stringencoding];

// if( [fm createfileatpath:filepath contents:contentdata attributes:nil] )

// nslog(@"create file ok!");

// else

// nslog(@"create file failed");

//複製檔案

nsstring *copypath = @"/users/huihui/desktop/aaa/test.txt";

// if( [fm copyitematpath:filepath topath:copypath error:nil] )

// nslog(@"copy succeed!");

// else

// nslog(@"copy failed!");

//移動檔案

nsstring *movepath = @"/users/huihui/desktop/love.txt";

if( [fm moveitematpath:copypath topath:movepath error:nil] )

nslog(@"move succeed!");

else

nslog(@"move failed!");

}return

0;}

IOS中UIViewController的建立

self.window uiwindow alloc initwithframe uiscreen mainscreen bounds self.window.backgroundcolor uicolor whitecolor self.window makekeyandvisible retur...

IOS開發中如何區分IOS版本

當前系統支援的最小版本 iphone os version min required 當前系統支援的最大版本 iphone os version max allowed 比如用iphone os sdk 3.1.2 編譯的程式 iphone os version min required iphon...

ios中讀寫檔案

在ios的開發中,經常遇到要讀寫檔案的情況,例如處理 採集資訊等,那麼在ios中對檔案的讀寫有兩種方式 1 使用nsdata 來將整個資料讀取到記憶體中 將檔案寫到檔案中 使用這種方式比較適合針對小檔案的讀寫,可以全部的讀到記憶體中處理,比如說全域性性的配置檔案等。2 使用c的api來讀取 在ios...