我正在尝试在 iOS 10.3 的文档文件夹中创建一个名为“abcó.txt”的文件。fopen() 成功,但未创建文件。知道为什么吗?以下是我的代码。
void test_fopen(){
const char *docsFolder = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] fileSystemRepresentation];
std::string filePath = std::string(docsFolder) + "/abc";
char oWithAcute[2] = {(char)0xC3, (char)0xB3, (char)0x00}; // the ó character to append
filePath = filePath + oWithAcute + ".txt";
FILE *fp = fopen(filePath.c_str(), "wb");
NSLog(@"Trying to create file using fopen: %s", filePath.c_str());
if( fp != NULL ){
NSLog(@"fopen() SUCCEEDED.");
}
else {
NSLog(@"fopen() FAILED.");
}
fclose(fp);
NSFileManager* fm = [NSFileManager defaultManager];
NSString *nsStr = [NSString stringWithUTF8String:filePath.c_str()];
if (![fm fileExistsAtPath: nsStr]) {
NSLog(@"File is NOT actually created.");
}
else{
NSLog(@"File is actually created.");
}
}