2016-06-28 76 views
2

我希望能够使用Android的内部存储。我发现了一些代码片段,如:如何在Xamarin中使用Android内部存储?

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

但我找不出应用程序在这里。

是否有针对或不同的角度任何解决方案? 谢谢:)

+0

应用是一个静态字段,它指的是您的应用程序 –

回答

5

使用此:

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

没有在我的范围内的任何GetFolderPath方法。您能否详细说明其范围? –

+0

你的范围是什么? Android项目? – jzeferino

+0

我想在我的Xamarin项目的Android部分中使用它。 –