如何在 Xamarin 中使用 Android 的内部存储? [英] How to use Internal Storage of Android in Xamarin?

查看:42
本文介绍了如何在 Xamarin 中使用 Android 的内部存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用 Android 的内部存储.我发现了一些代码片段,例如:

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 :)

推荐答案

使用这个:

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

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

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

这篇关于如何在 Xamarin 中使用 Android 的内部存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆