title: NSSearchPathForDirectoriesInDomains NSUserDomainMask
body: <p>Using URLConnection I am downloading a file from a url and storing that data to file in documents directory. When I receive response, when the didReceiveResponse: method called, I create file and move to end of that file this way: </p>
  
  <pre><code>NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:self.fileName];
  NSLog(@"filepath is %@",filePath);
  [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
  file = [[NSFileHandle fileHandleForUpdatingAtPath:filePath] retain];
  [file seekToEndOfFile];
  </code></pre>
  
  <p>where File is object of NSFileHandle class. Later while receiving data, whenever the didReceiveData:(NSData *)data method called, I store the received data to the file this way:</p>
  
  <pre><code>[file seekToEndOfFile];
  [file writeData:data];
  </code></pre>
  
  <p>Finally I close the file in connectionDidFinishLoading: method this way:</p>
  
  <pre><code>[file closeFile];
  </code></pre>
  
  <p>It was working when I build and run in my system. But when I copied to another system and tried to build I get this error : </p>
  
  <pre><code>Terminating app due to uncaught exception `'NSFileHandleOperationException'`, reason: '*** `-[NSConcreteFileHandle seekToEndOfFile]: No such file or directory'`
  </code></pre>
  
  <p>I refered <a href="http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS" rel="nofollow noreferrer">http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS</a> and 
  <a href="https://stackoverflow.com/questions/3179527/what-is-nssearchpathfordirectoriesindomains">What is NSSearchPathForDirectoriesInDomains?</a> for knowing about NSSearchPathForDirectoriesInDomain function but I am still not clear.</p>
  
  <p>Will <code>UserDomainMask</code> return the proper path depending on system and user in which the project exists. If so why I am getting such error?</p>
  
  <p>They say the path returned (stored in filepath) will be the path /Users//Library/Application Support/iPhone Simulator/User/Application//Documents where</p>
  
  <p> is the name of the user currently logged into the Mac OS X system on which the simulator is running and  is the unique ID of the app</p>
  
  <p>Can anyone help me, to understand why I am getting such error.</p>