ast*_*zed 14 iphone nsfilemanager nsdocumentdirectory
我正在使用下面的代码来保存图像 NSDocumentDirectory
-(BOOL)saveImage:(UIImage *)image name:(NSString *)name{
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [NSString pathWithComponents:[NSArray arrayWithObjects:dir, name, nil]];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
}
else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(image)];
[myFileHandle closeFile];
}
return ok;
}
Run Code Online (Sandbox Code Playgroud)
名称通常是下载图像的URL.
文件名的长度是否有约束?你知道有时网址可能超长...
谢谢
dea*_*rne 29
看一下syslimits.h中的PATH_MAX常量:91
...
#define PATH_MAX 1024 /* max bytes in pathname */
...
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式自行测试:
NSLog(@"%i", PATH_MAX);
Run Code Online (Sandbox Code Playgroud)
只想确认一下.
| 归档时间: |
|
| 查看次数: |
7628 次 |
| 最近记录: |