将文件保存在Documents/fileName下

<span style="font-family: Arial, Helvetica, sans-serif;">+ (NSString*)GetPath:(NSString*)imageName inFileName:(NSString*)fileName</span>
{
    //imageName : 要保存的图片/文件的名字
    //fileName  : Documents下创建的文件夹的名字
    
    NSString *paths = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:fileName];
    
    //创建文件夹
    BOOL creatManager = [[NSFileManager defaultManager] createDirectoryAtPath:paths withIntermediateDirectories:YES attributes:nil error:nil];
    NSString *fullPathToFile = [paths stringByAppendingPathComponent:imageName];
    NSLog(@"~~~~~~~~~~~~~~~~~~~~ fullPathToFile ~~~~~~~~~~~~~~~~~~  %@",fullPathToFile);

    return fullPathToFile;
 }


获取沙盒Documents路径

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];



获取沙盒下图片的路径 1


 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    NSString * filePath = [documentsDirectory stringByAppendingPathComponent:imageName];


获取沙盒下图片的路径 2
NSString *paths = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];


创建沙盒目录下文件夹,返回BOOL类型的值。 yes表示创建成功

[[NSFileManager defaultManager] createDirectoryAtPath:paths withIntermediateDirectories:YES attributes:nil error:nil]


获取沙盒目录文件夹下的图片路径

//paths为前面创建的文件夹路径(必须先创建文件夹再获取下面的路径)
NSString *fullPathToFile = [paths stringByAppendingPathComponent:imageName];




你可能感兴趣的:(ios,路径,保存图片,创建沙盒文件夹,Dcouments)