NSCachesDirectory不是我文件系统中的目录

编程入门 行业动态 更新时间:2024-10-18 16:45:00
本文介绍了NSCachesDirectory不是我文件系统中的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将某些内容存储在我的i​​Pad应用上的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-4​​9A9-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不是我文件系统中的目录

本文发布于:2023-05-28 06:57:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315134.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件系统   目录   NSCachesDirectory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!