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

时间:2013-06-02 16:18:34

标签: ios writetofile

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

 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)

1 个答案:

答案 0 :(得分:2)

我认为你的writeToFile方法是指一个变量descripPath,它应该是titlePath?

相关问题