开发者

Iphone file I/O operation and file structure

开发者 https://www.devze.com 2022-12-18 06:03 出处:网络
I want to write a iphone SDK program t开发者_高级运维o download and upload files from server. Server application is written in php.

I want to write a iphone SDK program t开发者_高级运维o download and upload files from server. Server application is written in php. But I m confusing following points in client application.

1) How can I download the file from server 2) How can I store it in iphone (accessing iphone file system) 3) How can I display all file in a directory to the users.

Can anybody help me ?


Create an NSURL

NSURL *  theURL = [NSURL URLWithString: @"http://foo.bar/whatever.php"];

Fetch the data with NSData

NSData * theData = [NSData dataWithContentsOfURL: theURL];

Save it to a file with the same NSData object

NSString * theFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString * theFileName = [theFolder stringByAppendingPathComponent:@"MyFile.txt"]
[theData writeToFile:theFileName atomically:true];

Use NSFileManager to list the files in the folder

NSError *error = nil;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray * filesInFolderStringArray = [fileManager contentsOfDirectoryAtPath:theFolder error:error];

This will give you an array of NSStrings with the names of the files in the folder.

0

精彩评论

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