Document下创建文件.

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES) objectAtIndex:0];

    BOOL isDir = NO;

    NSString *fanDir = [NSString stringWithFormat:@"%@/1",documentPath];

    if(![fileManager fileExistsAtPath:fanDir isDirectory:&isDir])

    {

        NSError *error = nil;

        [fileManager createDirectoryAtPath:fanDir withIntermediateDirectories:YES attributes:nil error:&error];

        NSLog(@"%@",[error localizedDescription]);

    }

    NSString *fileName = @"1.txt";

    NSString *fullPath = [NSString stringWithFormat:@"%@/%@",fanDir,fileName];

    [fileManager createFileAtPath:fullPath contents:nil attributes:nil];

你可能感兴趣的:(Document下创建文件.)