我,
我目前正在尝试使用以下方法将 NSMutable 数据保存在 plist 文件中:
[receivedData writeToFile:pathText atomically:YES]
请注意,接收到的数据来自 URLrequest 对象。这是我的代码:
NSURLConnection *connection01 = [[NSURLConnection alloc] initWithRequest:request01 delegate:self];
if(connection01)
{
//3.Create NSMutableData to receive data
//receiveddata is an instance declared elsewhere
receivedData = [NSMutableData data];
}
之后
//6.Mettre les informations téléchargées dans un plist.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"DOCUMENT DIRECTORY: %@", documentsDirectory);
NSString *pathNom = [documentsDirectory stringByAppendingPathComponent:@"InformationsUser.plist"];
NSString *pathText = @"/Users/victorbielak/Desktop/InformationUser.text";
[receivedData writeToFile:pathText atomically:YES];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
}
if(![[NSFileManager defaultManager] fileExistsAtPath:pathNom])
{
NSLog(@"file not found");
}
尽管我检查了 URL 下的信息是否已正确下载,但仍会出现错误消息“找不到文件”。有人知道该代码中缺少什么吗?我虽然 plist 是由 write to file 方法自动生成的。
谢谢您的答复。
胜利者