Reading content from file
NSString *contentPath = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"rtf"];
NSData *databuffer;
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:contentPath];
if (file == nil)
NSLog(@"Failed to open file");
databuffer = [file readDataToEndOfFile];
[file closeFile];
NSString *contentText =[[NSString alloc] initWithData:databuffer encoding:NSUTF8StringEncoding];
debugLog(@"%@",contentText);
[textView setText:contentText];
[conte开发者_如何转开发ntText release];
//[textView setText:[bookObj commentary]];
[self.view addSubview:textView];
Output:
i\ansicpg1252\cocoartf1038\cocoasubrtf320 {\fonttbl\f0\froman\fcharset0 Times-Roman;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww9000\viewh8400\viewkind0 \deftab720 \pard\pardeftab720\ql\qnatural
\f0\fs24 \cf0 A stream is a fundamental abstraction in programming: a sequence of bits transmitted serially from one point to another point. Cocoa provides three classes to represent streams and facilitate their use in your programs: NSStream, NSInputStream, and NSOutputStream. With the instances of these classes you can read data from, and write data to, files and application memory. You can also use these objects in socket-based
How to filter those bold data..???
You are trying to load RTF text into a plain string. Use NSAttributedString instead or convert your file to plain text.
I dont know if you were planning to edit this text as well or just display it but the only workable way I know is to use a UIWebView
NSString *path = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"rtf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
精彩评论