0

私はこれを試しました:

  BOOL success; 
  NSFileManager *fileManager = [NSFileManager defaultManager]; 
  NSError *error; 
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                     NSUserDomainMask, YES); 
  NSString *documentsDirectory = [paths objectAtIndex:0]; 


  NSString *writableDBPath = [documentsDirectory 
                              stringByAppendingPathComponent:@"FT1.docx"]; 
  success = [fileManager fileExistsAtPath:writableDBPath];
  NSLog(@"writableDBPath : %@", writableDBPath);

  NSString *str = [NSString stringWithContentsOfFile:writableDBPath 
                            encoding:NSUTF8StringEncoding error:&error];
  NSLog(@"My Data From File : %@",str);

しかし、str印刷し(null)ます。ファイルはドキュメント ディレクトリにあります。

それで、どうすればいいですか?

4

2 に答える 2

0

これを試して :

- (void)viewDidLoad
{
 webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [webView setDelegate:self];
    NSURL *url = [NSURL fileURLWithPath:yourFilePath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *document = [theWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerText"];
    NSLog(@"%@",document);
}
于 2012-07-27T11:26:56.123 に答える