中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

NSfileManager的使用方法

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用

總結(jié)了一下NSFileManager的一些常用方法,


    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ,NSUserDomainMask,YES);

   NSString *documentDirectory = [paths objectAtIndex:];

   NSLog(@"%@", documentDirectory);//路徑查看

    

     //1.創(chuàng)建文件夾

    NSFileManager *fileManager = [NSFileManagerdefaultManager];

   NSString *testDirectory = [documentDirectory stringByAppendingPathComponent:@"testbug1"];//創(chuàng)建文件夾

    //創(chuàng)建目錄

    [fileManager createDirectoryAtPath:testDirectorywithIntermediateDirectories:YESattributes:nilerror:nil];

    

    

    

    

    //2.創(chuàng)建文件

   NSString *test11 = [testDirectory stringByAppendingPathComponent:@"test111.txt"];

   NSString *test22 = [testDirectory stringByAppendingPathComponent:@"test222.txt"];

   NSString *string = @"寫入內(nèi)容1";

    [fileManager createFileAtPath:test11contents:[string dataUsingEncoding:NSUTF8StringEncoding]attributes:nil];

    [fileManager createFileAtPath:test22contents:[string dataUsingEncoding:NSUTF8StringEncoding]attributes:nil];

    

    //3.查看Document里所有文件

   NSArray *files = [fileManager subpathsAtPath:documentDirectory];

    //4.查看目錄里所有子文件

   NSArray *subfiles = [fileManager subpathsAtPath:testDirectory];

   NSLog(@"%@", subfiles);

   NSLog(@"%@", files);

    

    

    //5.更改到待操作的到目錄下

    [fileManager changeCurrentDirectoryPath:[documentDirectorystringByExpandingTildeInPath]];

    //創(chuàng)建文件filename文件名,contents文件的內(nèi)容

    NSString *fileName =@"testfilemanager.txt";

    NSArray *array = [[NSArrayalloc]initWithObjects:@"hello world",@"hello World", nil];


    [fileManagercreateFileAtPath:fileName contents:array attributes:nil];

    

    //6.刪除文件

    [fileManagerremoveItemAtPath:fileName error:nil];

    //7.復(fù)制文件后者給前者

   NSError *error;

    [fileManagercopyItemAtPath:test11 toPath:test22 error:&error];

    //8.移動(dòng)文件

   NSString *test33 = [documentDirectory stringByAppendingPathComponent:@"test33.txt"];

   if ([fileManager moveItemAtPath:test11toPath:test33 error:&error] !=YES) {

        NSLog(@"111%@", [errorlocalizedDescription]);

    }

    //9.文件是否存在

    if ([[NSFileManagerdefaultManager]fileExistsAtPath:@"/Users/dlios/Library/Application Support/iPhone Simulator/7.1/Applications/AC7B8788-BDCB-43AC-ABB6-8E9676CF94DC/Documents/testbug/test22333.txt"]) {

       NSLog(@"yes");

    }

   else NSLog(@"no");

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Android 伸縮動(dòng)畫xml配置

下一篇:硬盤大小轉(zhuǎn)換(B,KB,MB,GB,TB,PB之間的大小轉(zhuǎn)換) 的Java工具類