开发者

writeToFile path?

I'm wondering what is the default path when saving a file using the NSArray writeToFile:atomically: method...?

[array writeToFile:@"myFile.pl开发者_StackOverflow中文版ist" atomically:YES];

10x


It will save your file at Document directory.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath =  [paths objectAtIndex:0];

this is the path where your file will be saved.


I executed the following code:

if ([@"asdasdasd" writeToFile:@"foo123456.txt" atomically:YES]) {
    NSLog(@"+++");
} else {
    NSLog(@"---");
}

On the simulator the file foo123456.txt popped up in my root of my HD. The console printed +++, so the operation was successful.

On the device it failed, printing ---.


Use This Code.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *documentsDirectory = [paths objectAtIndex:0]; 

plistpath = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:@"Product.plist"]];

And then

[array writeToFile:path atomically:YES]; 

[Whatever [Array or Dictionary] you want to Write in Plist]

If it is still not creating the plist then check whether your array or dictionary must be empty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜