dawnarc
February 26, 2016, 2:33pm
1
I want to read text file by C++ std API '“fopen”, it’s successful on Windows, but read failed on Android.
FString projectDir = FPaths::GameDir();
FString path = projectDir + TEXT("Content/Resource/conf/role/Role.conf");
FILE * fp = ::fopen(TCHAR_TO_ANSI(*path), "rb");
if (fp)
{
TxtDebug->SetText(FText::FromString("TRUE++++++++++++"));
}
else
{
TxtDebug->SetText(FText::FromString("FALSE-----------"));
}
as I know, if there are some files should be inclued when Packaging, “Additional Non-asset Directories to Package” should be checked. even I check this setting, fopen still read file failed.
UE4 isn’t support c++ low level API on Android, I should use UE4 IO API instead of fopen
FString Content;
FFileHelper::LoadFileToString(Content, *(projectDir));
_ODIN
April 18, 2018, 6:19am
3
Android
extern FString GExternalFilePath;
FString path = GExternalFilePath + TEXT("Content/Resource/conf/role/Role.conf");
iOS
NSArray *docu = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docu_path = [docu firstObject];
FString RootPath(docu_path);
FString path = RootPath + TEXT("Content/Resource/conf/role/Role.conf");
if you can’t open the file with Android,you’ll need READ_EXTERNAL_STORAGE permission.