How to use Internal Storage of Android in Xamarin?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 08:09:08

问题


I want to be able to use Android's internal storage. I found some code snippets like:

 string path = Application.Context.FilesDir.Path;
 var filePath = Path.Combine(path, "test.txt");
 System.IO.File.WriteAllText(filePath, "Hello World");

But I could not figure out what Application is in here.

Is there any solution for that or different perspective? Thanks :)


回答1:


Use this:

string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string filename = System.IO.Path.Combine(path, "testfile.txt");

// Write
using (var streamWriter = new StreamWriter(filename, true))
{
    streamWriter.WriteLine(DateTime.UtcNow);
}

// Read
using (var streamReader = new StreamReader(filename))
{
    string content = streamReader.ReadToEnd();
    System.Diagnostics.Debug.WriteLine(content);
}


来源:https://stackoverflow.com/questions/38075824/how-to-use-internal-storage-of-android-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!