【问题标题】:How to use Internal Storage of Android in Xamarin?如何在 Xamarin 中使用 Android 的内部存储?
【发布时间】:2016-06-28 12:07:50
【问题描述】:

我希望能够使用 Android 的内部存储。我发现了一些代码 sn-ps,例如:

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

但我不知道这里有什么应用程序。

对于那个或不同的观点有什么解决方案吗? 谢谢:)

【问题讨论】:

  • Application 是一个静态字段,引用您的应用程序

标签: android xamarin storage internal


【解决方案1】:

使用这个:

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);
}

【讨论】:

  • 我的范围内没有任何 GetFolderPath 方法。请您详细说明其明确而全面的范围吗?
  • 你的范围是什么?安卓项目?
  • 我想在我的 Xamarin 项目的 Android 部分中使用它。
  • 我会的。我目前正在处理另一个问题。我只是想告诉你:)
  • 因为这是Personal 文件夹,所以你不需要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 2021-06-12
  • 2019-03-02
  • 1970-01-01
  • 1970-01-01
  • 2014-04-07
相关资源
最近更新 更多