0

Silverlight アプリケーションの分離ストレージ内のファイルにいくつかのバイトが書き込まれています。このファイルの名前は「data.dat」です。次のコードを使用して、Isolated Storage に書き込みました。

// Store the data in isolated storage
var bytes = GetData();
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
  using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("data.dat", FileMode.Create, storage))
  {
    file.Write(bytes, 0, bytes.Length);
  }
}

私の質問は、バイトがそこにあるときに、分離ストレージからバイトを取得するにはどうすればよいですか? 私が見るものはすべて文字列を返します。しかし、バイナリ データを返す方法がわかりません。

ありがとう。

4

1 に答える 1

3

このコードはバイトを取得します -

byte[] output;

using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
   IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.OpenFile("data.dat", FileMode.Open, FileAccess.Read);

   output = new byte[isolatedStorageFileStream.Length];
   isolatedStorageFileStream.Read(output, 0, output.Length);
   isolatedStorageFileStream.Dispose();
}
于 2010-11-01T21:04:26.920 に答える