在我的设备中写入 NSData 时出现问题 [英] Problem writing NSData in my device
本文介绍了在我的设备中写入 NSData 时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释一下为什么我的代码不起作用?
Can someone explain me why my code doesn't work?
//get the documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the
//documents directory:
NSString *fullFileName = [NSString stringWithFormat:@"%@/subscriptions", documentsDirectory];
[dataReply writeToFile:fullFileName atomically:NO];
NSData *getData=[[NSData alloc]initWithContentsOfFile:fullFileName];
事实上,如果我尝试
NSString *string = [[NSString alloc] initWithData:getData encoding:NSASCIIStringEncoding];
如果我加载 myData 而不将其保存到我的设备,它就可以工作!(所以我确定我的数据不为空)
while if I load myData without save it to my device it works! (So I'm sure that my data is not empty)
推荐答案
试试这个,
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the
//documents directory:
NSString *fullFileName = [NSString stringWithFormat:@"%@/subscriptions", documentsDirectory];
[dataReply writeToFile:fullFileName atomically:NO];
Nsdata *getData=[fullFileName dataUsingEncoding:NSUTF8StringEncoding];
这篇关于在我的设备中写入 NSData 时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文