开发者

Creating a text file in ipad application

How to create a file and save it as a text file in iPad through the application?. If I had to read that file at a later stage how to specify the absolute path. Could some one help on this.

Is it possible to display the text f开发者_StackOverflow社区ile created using the iPad app in the device homescreen, so that user's will be able to modify it.


To Write a file to documents directory use following code, (you may need to do some syntax correction as not tested)

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir =[documentPaths objectAtIndex:0];
NSString *filePath = [documentsDir stringByAppendingPathComponent:yourFileName];

NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:filePath contents:nil attributes:nil];

// Open a handle to it.
NSFileHandle* pfile = [NSFileHandle fileHandleForWritingAtPath:filePath];

[pfile writeData:[[NSString stringWithString:@"YourData"] dataUsingEncoding:NSUTF8StringEncoding]];

And to provide user facility to edit it you can use, one option I can see.

Enable "Application supports iTunes file sharing"in plist file of the application so that user would be able to see the documents through the itunes.

You need to read and check the content though to track the changes done to document.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜