title: Overwriting current contents in file
body: <p>I want to overwrite the current data at the beginning of the my text file called data.txt (in my resources folder). There will always be only one line (no spaces or anything) and I want this line to be overwritten when appropriate. This is how I have been doing it so far but this only writes contents at the end of the file and doesn't begin from the beginning aka overwriting the line I need. If anyone can help me it would be appreciated. Thanks!</p>
  
  <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
  NSString *documentsDirectory = [paths objectAtIndex:0];
  
  //append filename to docs directory
  NSString *myPath =  [documentsDirectory stringByAppendingPathComponent:@"data.txt"];
  fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:myPath];
  
  writtenString= [[NSString alloc]initWithFormat:@"%d", message];     
  
  [fileHandle seekToEndOfFile];
  [fileHandle writeData:[writtenString dataUsingEncoding:NSUTF8StringEncoding]];
  
  [writtenString release];
  </code></pre>