0

我从网上下载了一个 XML 文件并将其保存在一个文件夹中。使用这些代码

NSURL *goo = [[NSURL alloc]initWithString:@"......xml"];
NSData *data = [[NSData alloc] initWithContentsOfURL:goo]; 
NSString *xml = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
NSString *documentsDirectory = @"/Users/MacBook/Desktop/Bebegim_Icin_Yarisiyorum/Milyoner/Class";   
NSString *xmlFilePath = [documentsDirectory stringByAppendingPathComponent:@"qpack1.xml"];
[xml writeToFile:xmlFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

类文件夹位于 myProject 文件夹中。

但是Apple没有这个路径。我需要说将xml文件保存在我的项目文件夹的Class文件夹中。

/Users/MacBook/Desktop/Bebegim_Icin_Yarisiyorum/Milyoner/Class 

谁能帮助我,我应该说../Class.Class./Class

在创建 documentDirectory 时我应该说什么。

4

1 回答 1

1

尝试:

NSString *documentsDirectory = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents/qpack2.xml"];

或者:

NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
NSString *docsPAth = [pathArray objectAtIndex:0];
NSString *documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"qpack2.xml"];
于 2013-03-14T12:44:51.363 回答