0
我正在嘗試將數據寫入文件,然後再次讀出。它看起來像我有正確的結構來寫它,但是當我讀它時沒有出現。有人可以看看我是否缺少一些東西。這裏是代碼片段爲什麼不能將數據寫入文件
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'? – Graham
好吧我是盲目的謝謝你額外的眼睛是今天早上2點,當我寫這明顯睡眠沒有讓我看到任何更好的地方作爲一個答案,我會接受它。 –
@格拉漢姆看起來像你有答案... –