• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: creating files to write data to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating files to write data to?


  • Subject: Re: creating files to write data to?
  • From: FTB Accounts <email@hidden>
  • Date: Thu, 14 Aug 2008 17:42:40 -0700 (PDT)

I saw this post on the list previously.

However I am still unable to write to a file... I have tried everything...
Here is my code for my main.m file. What am I missing?

I am running a Mac OS X 10.4.11 and editing with Xcode 2.2.1

HERE IS MY CODE FOR main.m:

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[]) {

/* Define what file to write to on local hard drive...  */
	NSString *fname="/Applications/xampp/xamppfiles/htdocs/data/data.txt";

/* CREAT EMPTY FILE? */
	[@"" writeToFile:fname atomically:NO];

	NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];

/* WRITE DATA TO FILE: THIS IS A TEST */
	[fh writeData:"THIS IS A TEST"];
	[fh closeFile];


    return NSApplicationMain(argc,  (const char **) argv);
}


/* end main.m */
#############################################

Subject: Re: creating files to write data to?
From: Ondra Cada <email@hidden>
Date: Fri, 12 Mar 2004 00:37:49 +0100
Ken,

On Thursday, Mar 11, 2004, at 23:51 Europe/Prague, Ken Hawkins wrote:

how can i create a 0 length file that i will throughout the processes of my app write data to. this is mixed string and binary data.

Do you insist on this workflow?

In a vast majority of cases you just write the complete file atomically, like

NSData *d=... the contents of file computed somehow ...
[d writeToFile:FILENAME atomically:YES];

Nevertheless, you can use NSFileHandle

NSString *fname=...;
[@"" writeToFile:fname atomically:NO]; // create the empty file
NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];
...
[fh writeData:... partial contents of file computed somehow ...]; // as many times as you want to
...
[fh closeFile];
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: creating files to write data to?
      • From: Devon Ferns <email@hidden>
    • Re: creating files to write data to?
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Animating a view along a path
  • Next by Date: RE: Threading problem using AsyncSocket
  • Previous by thread: Re: Changing NSTextFieldCells' editing appearance?
  • Next by thread: Re: creating files to write data to?
  • Index(es):
    • Date
    • Thread