gpt4 book ai didi

android - 如何在 Xamarin 中使用 Android 的内部存储?

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:26 26 4
gpt4 key购买 nike

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

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

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

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

最佳答案

使用这个:

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

关于android - 如何在 Xamarin 中使用 Android 的内部存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38075824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com