2016-06-28 71 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部分中使用它。 –