2008年10月26日星期日

iPhone SDK中使用fopen && open

需要引入
fopen与open都可以使用,在Application_Home/Documents/这个目录下是可以使用"写"的操作。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//creates paths so that you can pull the app's path from it

NSString *documentsDirectory = [paths objectAtIndex:0];
//gets the applications directory on the users iPhone

NSString *scoreFileName = @"/SavedScores";
//sets the name of the file name to be SavedScores

const char *scoreFile = [[documentsDirectory stringByAppendingString:scoreFileName] UTF8String]; //appends scoreFileName to the end of documentsDirectory & converts it to a const char so that fopen can deal with it.

/*
FILE * pFile;
if((pFile = fopen ( scoreFile , "w" )) != NULL) { //opens file & positions to beginning
fclose(pFile);
}
*/

int fd;

fd = open(scoreFile, O_APPEND | O_WRONLY, 0755);

close(fd);

没有评论: