How do i write a file to the desktop?


Okay, so I had the same question someone else asked, “where is the file.” I could see how you gave instructions about finding it. But I’d like to know what code or path would I use to write the file to the desktop?

This would be helpful to me, because I really want to learn how to read and write files to some that I can easily look at and examine them.

Thanks so much,

Tim M


Never mind, I figured it out my answer by reading a post from

Re: /tmp
by Orangecicle » Sun Jan 01, 2012 11:38 am

Instead of using /tmp, there is a simple solution. Go to any document in your user documents folder and Get Info on that file. Use the path listed there instead in place of /tmp. For me, that path with Aaron’s text file at the end is: @"/Users/jbradleyhorn/Documents/cool.txt":

[str writeToFile:@"/Users/jbradleyhorn/Documents/cool.txt" atomically:YES encoding:NSUTF8StringEncoding error:NULL];

Posts: 38
Joined: Tue Nov 29, 2011 11:49 pm



I think the authors should have included a challenge (or two) to use the information in Finding special directories

Could adapt the sample program to write the file to the desktop (using the code in the book). (NSDesktopDirectory…)

Even just reading the entries in the trash bin could have been a good challenge. (NSTrashDirectory…)