title: Read/write file in Documents directory problem
body: <p>I am trying to write a very basic text string to my documents directory and work from there to later save other files etc.</p>
  
  <p>I am currently stuck with it not writing anything into my Documents directory</p>
  
  <p>(In my <code>viewDidLoad</code>)</p>
  
  <pre><code>NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
  NSString *documentsDirectory = [pathArray objectAtIndex:0];
  
  NSString *textPath = [documentsDirectory stringByAppendingPathComponent:@"file1.txt"];
  NSString *text = @"My cool text message";
  
  [[NSFileManager defaultManager] createFileAtPath:textPath contents:nil attributes:nil];
  [text writeToFile:textPath atomically:NO encoding:NSUTF8StringEncoding error:NULL];
  NSLog(@"Text file data: %@",[[NSFileManager defaultManager] contentsAtPath:textPath]);
  </code></pre>
  
  <p>This is what gets printed out:</p>
  
  <blockquote>
    <p>2011-06-27 19:04:43.485 MyApp[5731:707] Text file data: (null)</p>
  </blockquote>
  
  <p>If I try this, it also prints out null:</p>
  
  <pre><code>NSLog(@"My Documents: %@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:NULL]);
  </code></pre>
  
  <p>What have I missed or am I doing wrong while writing to this file?
  Might it be something I need to change in my plist or some frameworks/imports needed?</p>
  
  <p>Thanks</p>
  
  <p><strong>[EDIT]</strong>
  I passed a NSError object through the writeToFile and got this error:</p>
  
  <blockquote>
    <p>Error: Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x12aa00 {NSFilePath=/var/mobile/Applications/887F4691-3B75-448F-9384-31EBF4E3B63E/Documents/file1.txt, NSUnderlyingError=0x14f6b0 "The operation couldn’t be completed. Not a directory"}</p>
  </blockquote>
  
  <p><strong>[EDIT 2]</strong>
  This works fine on the simulator but not on my phone :/</p>