I'm trying to write a file to the internal storage of my phone using Xamarin. So far, I tried to follow this tutorial and found that related question. My code looks as follows:
public async Task WriteDataToFile() {
string PersonalFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
System.Diagnostics.Debug.WriteLine("PersonalFolderPath: " + PersonalFolderPath);
var backingFile = Path.Combine(PersonalFolderPath, "count.txt");
System.Diagnostics.Debug.WriteLine("backingFile: " + backingFile.ToString());
if (!System.IO.File.Exists(backingFile)) {
var newfile = new Java.IO.File(backingFile);
using (FileOutputStream outfile = new FileOutputStream(newfile)) {
string line = "The very first line!";
outfile.Write(System.Text.Encoding.ASCII.GetBytes(line));
outfile.Close();
}
}
}
This is the debug output I receive:
[0:] PersonalFolderPath: /data/user/0/MyApp.Android/files
[0:] backingFile: /data/user/0/MyApp.Android/files/count.txt
After executing the code, I try to access the newly created file from my PC by checking the path "This PC\Galaxy S8\Phone\Android\data\MyApp.Android\files" but unfortunately it's not there. What am I doing wrong here? Help is highly appreciated.