gurehbgui
gurehbgui

Reputation: 14684

How to save and read a byte[] into a IsolatedStorageFile

i know how to save a string into the IsolatedStorageFile but what about a byte[] ? for a string i do:

string enc = "myString";
using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var stream = iso.OpenFile("fileName", FileMode.Create))
    {
        var writer = new StreamWriter(stream);
        writer.Write(enc);
        writer.Close();
     }
} 

EDIT: okay i know now how to write, but how to read out the byte[] again?

Upvotes: 1

Views: 756

Answers (2)

Pol
Pol

Reputation: 5134

Use BinaryWriter instead of StreamWriter.

Upvotes: 3

Kevin Gosse
Kevin Gosse

Reputation: 39007

To write a byte array, instead of enclosing your stream in a StreamWriter, use directly stream.Write. Or use a BinaryWriter.

For instance:

stream.Write(byteArray, 0, byteArray.Length);

Upvotes: 2

Related Questions