NSData的writeToFile方法因服务器地址而失败

时间:2010-04-07 20:46:13

标签: cocoa nsdata

我正在尝试将NSData对象写入类似的目录;

[myData writeToFile:[NSString stringWithFormat:@"%@/%@.txt", path, filename] atomically:YES];

我没有收到任何错误或警告,但我假设写入失败,因为path变量的格式为afp://10.0.0.20/username/Desktop。我已连接到网络共享。

我是否需要修改字符串或采取不同的方法?

编辑:推荐后尝试了以下方法,但失败了

NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"afp://10.0.0.20/username/Desktop/filename.txt"]];
[post setHTTPMethod: @"POST"];
[post setHTTPBody:horreumImageDataNewThread];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];

TIA, 瑞奇。

1 个答案:

答案 0 :(得分:1)

你从哪里获得afp path字符串?您通常会使用以下路径写入网络卷:

/Volumes/NameOfMountedVolume/path/to/file

此外,您应该使用-stringByAppendingPathComponent:的{​​{1}}方法来连接路径:

NSString