gpt4 book ai didi

ios - 为什么不能将数据写入文件

转载 作者:行者123 更新时间:2023-11-28 22:33:07 25 4
gpt4 key购买 nike

我正在尝试将数据写入文件,然后再将其读出。看起来我有正确的结构来编写它,但是当我阅读它时没有任何显示。有人可以看看我是否遗漏了什么。这是代码片段

 NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

//LOADING TITLE ONTO DEVICE///////
NSString *title =[NSString stringWithFormat:@"%@_title.txt",[[prodlist objectAtIndex:indexPath.row] objectForKey:@"appSKU"]];
DLog(@"Title = %@",title);
NSString *titlePath = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",title]]; //add our title to the path
DLog(@"Path = %@",titlePath);
if(![[NSFileManager defaultManager] fileExistsAtPath:titlePath]) {
DLog(@"Content = %@",product.localizedTitle);
[product.localizedTitle writeToFile:descripPath atomically:NO];

}
//////////////////////////////////
//cell.AppTitle.text = product.localizedTitle;
DLog(@"Path1 = %@",titlePath);
DLog(@"Content1 = %@",[NSString stringWithContentsOfFile:titlePath encoding:NSUTF8StringEncoding error:nil]);
cell.AppTitle.text = [NSString stringWithContentsOfFile:titlePath encoding:NSUTF8StringEncoding error:nil];

我的日志文件至少向我表明我有正确的路径在这两次尝试中,尽管似乎没有任何返回

2013-06-02 09:15:15.698 IMOB[35034:907] <MasterViewController.m:(144)> Title = app_0101_title.txt
2013-06-02 09:15:15.699 IMOB[35034:907] <MasterViewController.m:(146)> Path = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0101_title.txt
2013-06-02 09:15:15.700 IMOB[35034:907] <MasterViewController.m:(148)> Content = Relax Sleep Well Full
2013-06-02 09:15:15.707 IMOB[35034:907] <MasterViewController.m:(161)> Path1 = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0101_title.txt
2013-06-02 09:15:15.709 IMOB[35034:907] <MasterViewController.m:(162)> Content1 = (null)
2013-06-02 09:15:15.725 IMOB[35034:907] <MasterViewController.m:(144)> Title = app_0102_title.txt
2013-06-02 09:15:15.726 IMOB[35034:907] <MasterViewController.m:(146)> Path = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0102_title.txt
2013-06-02 09:15:15.728 IMOB[35034:907] <MasterViewController.m:(148)> Content = Lose Weight Now
2013-06-02 09:15:15.735 IMOB[35034:907] <MasterViewController.m:(161)> Path1 = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0102_title.txt
2013-06-02 09:15:15.738 IMOB[35034:907] <MasterViewController.m:(162)> Content1 = (null)

最佳答案

我认为您的 writeToFile 方法引用了一个变量 descripPath,它应该是 titlePath?

关于ios - 为什么不能将数据写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16884713/

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