how to store file contents to ip开发者_运维问答hone's internal memory using xcode ?
I want to store XML file to iPhone's internal memory.
You can read hold the xml data in NSData and store the file in private folder ( avaible only for application )
below is code for saving file
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableString* str = [[NSMutableString alloc] initWithCapacity:300];
[str appendString:documentsDirectory];
[str appendString:@"/"];
[str appendString:aName];
NSFileManager *fileManager = [NSFileManager defaultManager];
[/*NSData*/ writeToFile:str atomically:YES];
if(str)
{
[str release];
str = nil;
}
if(fileManager)
{
[fileManager release];
fileManager = nil;
}
[pool release];
精彩评论