1

I have a byte array and need to save it to a file.

I have tried the below code:

File.WriteAllBytes("form.txt", byteArray);

string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "form.txt");

I have referred https://stackoverflow.com/a/19455387/15265496 for the implementation.

I am looking for the file in Android emulator. Where will the file get saved from first line?

Should I create a form.txt in the application local folder?

Is there any alternative way to do the same?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 1
    Probably depends on [your application's current working directory](https://learn.microsoft.com/en-us/dotnet/api/system.environment.currentdirectory?view=net-5.0). – Uwe Keim Feb 23 '21 at 09:55

2 Answers2

0

You can find the appropriate folder using Environment.SpecialFolder.LocalApplicationData

string fileExactLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "form.txt");

You can find more information at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=windows

Gurhan Polat
  • 696
  • 5
  • 12
0

You cannot access the file system of an Android emulator instance via explorer or finder.

As per the Microsoft docs, if you want to store a file in Android, you can always use the application's files folder which is accessible through:

var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

A file saved to that folder will go to

/data/user/0/com.companyname/files
Philipp
  • 61
  • 6