iPhone SDK中使用fopen and open

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);

这些代码仅仅为了测试,并不规范。