NSCachesDirectory不是我文件系统中的目录 [英] NSCachesDirectory not a directory in my file system
问题描述
我正在尝试将某些内容存储在我的iPad应用上的Caches文件夹中。
I'm trying to store something in my Caches folder on my iPad app.
NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cachePath = [cachePathArray lastObject];
当我打印出返回的文件路径时,我得到:
And when I print out the returned filepath, I get:
/ Users / Gela / Library / Application Support / iPhone
Simulator / 5.0 / Applications / 3FF7EB1A-49A9-4B13-ADC4-DF0662BA724B / Library / Caches
/Users/Gela/Library/Application Support/iPhone Simulator/5.0/Applications/3FF7EB1A-49A9-4B13-ADC4-DF0662BA724B/Library/Caches
然而,当我导航到硬盘上的那个文件夹时,Caches不是文件夹而是模糊的文档文件。
However, when I navigate to that folder on my hard drive, "Caches" is not a folder but a vague "document" file.
为什么它不是文件夹以及我如何写入我的缓存的任何想法?
Any ideas why it's not a folder and how I can write to my Cache?
推荐答案
可能模拟器
没有缓存
目录。你在设备上试试这个......
Maybe Simulator
does not have Caches
dir. You try this on device...
你可以像这样访问 Caches
目录。我使用此方法获取文件数据...
You can access the Caches
directory like this. I use this method for getting file data...
- (NSString *)getFileData: (NSString *)fileDirPath
{
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *myPath = [myPathList objectAtIndex:0];
NSError *err = nil;
NSString *fData = @"";
myPath = [myPath stringByAppendingPathComponent:fileDirPath];
if([[NSFileManager defaultManager] fileExistsAtPath:myPath])
{
fData = [NSString stringWithContentsOfFile:myPath encoding:NSUTF8StringEncoding error:&err];
if(err) NSLog(@"getFileData() - ERROR: %@",[err localizedDescription]);
}
else
{
NSLog(@"getFileData() - ERROR: This file '%@' does not exist",myPath);
}
return fData;
}
这篇关于NSCachesDirectory不是我文件系统中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!