3
我想創建一個名爲'abcó.txt'在iOS 10.3文檔文件夾中的文件。 fopen()成功,但文件沒有創建。任何想法爲什麼?以下是我的代碼。問題與fopen在ios 10.3當文件名有unicode(utf8)字符
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.");
}
}