zoukankan      html  css  js  c++  java
  • ios中文件夹文件的创建和删除

     //1、文件夹、文件的创建和删除

        NSFileManager *fileManager=[NSFileManager defaultManager];

        NSString *filePath=@"/Users/apple/Desktop/";

        

        NSError *error;

     //判断当前文件夹是否存在

        BOOL isExist=[fileManager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@",filePath] error:&error];

     

        //创建子文件夹

        BOOL isExist1=[fileManager createDirectoryAtPath:[NSString stringWithFormat:@"%@/hello"] withIntermediateDirectories:YES attributes:nil error:&error];

        //在指定路径下创建文件内容

     BOOL isExist2=[fileManager createFileAtPath:[NSString stringWithFormat:@"%@/hello/temp"] contents:[@"hello world" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];

        

        BOOL isExist3=[fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/hello"] error:&error];

        

        //2、文件的读取和写入

        NSFileHandle *handle=[NSFileHandle fileHandleForReadingAtPath:[NSString stringWithFormat:@"%@/hello",filePath]];

        //读取文件的内容

        NSData *fileData=[handle readDataToEndOfFile];

        

        NSString *fileStr=[[NSString alloc]initWithData:fileData encoding:NSUTF8StringEncoding];

        //文件的读取

        NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:[NSString stringWithFormat:@"%@/hello",filePath]];

        

        NSData *writeData=[@"hello" dataUsingEncoding:NSUTF8StringEncoding];

        //定位到文件最后

        [fh seekToEndOfFile];

        //写入文件

        [fh writeData:writeData];

     

     

  • 相关阅读:
    Django 类方式view进行进行用户验证
    Django-发送注册、忘记密码邮件验证-send_mail
    Django-当前菜单激活状态-模版 request | slice
    django url路由参数错误
    video.js不能控制本地视频或者音频播放时长
    Django中url使用命名空间的错误
    python_求相邻数
    scrapy_移除内容中html标签
    scrapy-redis功能简介
    Determining IP information for eth0...failed 错误解决
  • 原文地址:https://www.cnblogs.com/bigant9527/p/14047865.html
Copyright © 2011-2022 走看看