In the Android/data path I can see that a folder with my project name was created that contains a cache folder, but the files folder doesn't get created, nor the file I am trying to write.
In fact, you have writen the file successfully. This is because the file with path Path.Combine(FileSystem.AppDataDirectory, filename)
can't be found by the Android System File Manager. But you can find it by the Android Studio's Device File Explorer. You can try to read the file to check if you write it successfully or not.
In addtion, if you want to create the file in the Android/data/.../projectname path, you can use Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath
, such as:
string targetFile;#if ANDROIDtargetFile = Path.Combine(Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath, filename);#elsetargetFile = Path.Combine(FileSystem.AppDataDirectory, filename);#endif
====================
The FileSystem.Current.OpenAppPackageFileAsync
is used to read the bundled file not the device local file. You can use the following code to read the file:
public async Task<string> ReadTextFile(string filePath) { try { using (var sr = new StreamReader(filePath)) { return sr.ReadToEnd(); }; } catch { return ""; } }