2016-06-28 23 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

アプリケーションは、私の範囲内の任意GetFolderPath方法はありません、あなたのアプリケーション –

答えて

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

を指し、静的フィールドです。明示的で徹底的な範囲を指定してください。 –

+0

あなたの範囲は何ですか? Androidプロジェクトですか? – jzeferino

+0

私のXamarinプロジェクトのAndroid部分でそれを使いたいです。 –

関連する問題