如何在 Xamarin 中使用 Android 的内部存储?
How to use Internal Storage of Android in Xamarin?
我希望能够使用 Android 的内部存储空间。我发现了一些代码片段,例如:
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 的内部存储空间。我发现了一些代码片段,例如:
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);
}