zoukankan      html  css  js  c++  java
  • iOS 关于文件操作 NSFileManager

    • 创建文件夹
      + (BOOL)creatDir:(NSString *)path {
          if (path.length==0) {
              return NO;
          }
          NSFileManager *fileManager = [NSFileManager defaultManager];
          BOOL isSuccess = YES;
          BOOL isExist = [fileManager fileExistsAtPath:path];
          if (isExist==NO) {
              NSError *error;
              if (![fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
                  isSuccess = NO;
                  NSLog(@"creat Directory Failed:%@",[error localizedDescription]);
              }
          }
          return isSuccess;
      }
      

        

    • 创建文件
      + (BOOL)creatFile:(NSString*)filePath {
          if (filePath.length==0) {
              return NO;
          }
          NSFileManager *fileManager = [NSFileManager defaultManager];
          if ([fileManager fileExistsAtPath:filePath]) {
              return YES;
          }
          NSError *error;
          NSString *dirPath = [filePath stringByDeletingLastPathComponent];
          BOOL isSuccess = [fileManager createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error];
          if (error) {
              NSLog(@"creat File Failed:%@",[error localizedDescription]);
          }
          if (!isSuccess) {
              return isSuccess;
          }
          isSuccess = [fileManager createFileAtPath:filePath contents:nil attributes:nil];
          return isSuccess;
      }
      

        

    • 写入文件
      + (BOOL)writeToFile:(NSString*)filePath contents:(NSData *)data {
          if (filePath.length==0) {
              return NO;
          }
          BOOL result = [self creatFile:filePath];
          if (result) {
              if ([data writeToFile:filePath atomically:YES]) {
                  NSLog(@"write Success");
              }else{
                  NSLog(@"write Failed");
              }
          }
          else{
              NSLog(@"write Failed");
          }
          return result;
      }
      

        

    • 追加数据
      + (BOOL)appendData:(NSData*)data withPath:(NSString *)filePath {
          if (filePath.length==0) {
              return NO;
          }
          BOOL result = [self creatFile:filePath];
          if (result) {
              NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
              [handle seekToEndOfFile];
              [handle writeData:data];
              [handle synchronizeFile];
              [handle closeFile];
          }
          else{
              NSLog(@"appendData Failed");
          }
          return result;
      }

      

  • 相关阅读:
    70. Climbing Stairs(动态规划)
    53. Maximum Subarray(动态规划)
    PAT 1045. Favorite Color Stripe
    PAT 1044. Shopping in Mars
    分治策略
    时间复杂度和空间复杂度分析(转载)
    [转载]论坛中某位达人自己编写的Morlet连续小波变换程序
    连续小波时频图绘制原理    连续小波变换尺度与信号频率的关系
    Matlab中wavedec使用學習及詳解
    [转载]转载:小波分解层数与尺度的关系
  • 原文地址:https://www.cnblogs.com/gwca/p/8399146.html
Copyright © 2011-2022 走看看