0

我有一些字节写入我的 Silverlight 应用程序的隔离存储中的文件。该文件名为“data.dat”。我使用以下代码将其写入独立存储:

// 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 回答