文件名的最大长度 [英] max length of file name
本文介绍了文件名的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码将图像保存在 NSDocumentDirectory
i am using the code below to save an image in the 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;
}
名称通常是下载图像的网址。
the name is usually the url of where the image was downloaded.
文件名长度有限制吗?你知道有时网址可能超长...
is there a constraint on the length of the file name? you know sometimes urls may be super long...
谢谢你
推荐答案
查看syslimits.h中的PATH_MAX常量:91
Taking a look at the PATH_MAX constant in syslimits.h:91
...
#define PATH_MAX 1024 /* max bytes in pathname */
...
您可以自己测试一下通过这样做:
You can test this yourself by doing :
NSLog(@"%i", PATH_MAX);
只是为了确保。
这篇关于文件名的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文