gpt4 book ai didi

ios - 读取文档文件夹中的文本文件 - Iphone SDK

转载 作者:可可西里 更新时间:2023-11-01 04:09:34 25 4
gpt4 key购买 nike

我有以下代码:

    NSString *fileName = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentDownload"];
NSString *fullPath = [NSBundle pathForResource:fileName ofType:@"txt" inDirectory:[NSHomeDirectory() stringByAppendingString:@"/Documents/"]];
NSError *error = nil;

[textViewerDownload setText:[NSString stringWithContentsOfFile:fullPath encoding: NSUTF8StringEncoding error:&error]];
  • textviewerdownload 是显示文件文本的 textview。实际文件名存储在名为 recentDownloadNSUserDefault 中。

  • 当我构建它时,我点击了它所在的按钮,然后我的应用程序崩溃了

  • 语法有问题还是只是简单的错误?

最佳答案

NSBundle 类用于在您的应用程序包中查找内容,但 Documents 目录在包之外,因此您生成路径的方式将不起作用。试试这个:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);

NSString *fullPath = [[paths lastObject] stringByAppendingPathComponent:@"recentDownload.txt"];

关于ios - 读取文档文件夹中的文本文件 - Iphone SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2709705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com