2010-11-01 63 views
0

我的Silverlight應用程序中有一些字節寫入獨立存儲中的文件。這個文件被命名爲「data.dat」。我使用下面的代碼就寫信給獨立存儲:從Silverlight中的IsolatedStorage中讀取二進制數據

// 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); 
    } 
} 

我的問題是,我該如何找回從獨立存儲字節,一旦他們在那裏?我看到的一切都會返回一個字符但我沒有看到返回二進制數據的方法。

謝謝。

回答

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

在你的代碼什麼是「數據」? – lamarant 2011-08-09 22:35:48

+0

萊昂 - 我認爲這意味着'輸出'。因此,要麼改變'數據'爲'輸出',要麼改變字節[]輸出;到byte []數據; – 2011-08-17 01:42:23