新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)IOS教程:iOS文件處理
iOS文件處理
簡(jiǎn)介
文件處理不能直觀的通過(guò)應(yīng)用程序來(lái)解釋,我們可以從以下實(shí)例來(lái)了解IOS的文件處理。

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)建站將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。
IOS中對(duì)文件的操作. 因?yàn)閼?yīng)用是在沙箱(sandbox)中的,在文件讀寫權(quán)限上受到限制,只能在幾個(gè)目錄下讀寫文件。
文件處理中使用的方法
下面列出了用于訪問(wèn)和操作文件的方法的列表。
以下實(shí)例你必須替換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");
}
比較兩個(gè)文件的內(nèi)容
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");
}
移動(dòng)文件
if([fileManager moveItemAtPath:@"FilePath1"
toPath:@"FilePath2" error:NULL]){
NSLog(@"Moved successfully");
}
復(fù)制文件
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文件處理
網(wǎng)頁(yè)路徑:http://www.5511xx.com/article/ccssgee.html


咨詢
建站咨詢
