在plist文件中保存NSMutable Data对象

时间:2012-05-03 15:57:07

标签: iphone objective-c plist nsdata writetofile

我,

我目前正尝试使用以下方法将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是由写入文件方法自动生成的。

感谢您的回复。

维克多

1 个答案:

答案 0 :(得分:0)

您应该使用pathNom而不是pathText ..:)