基本上,我需要知道如何在 .net 4.5 中编写这段代码。我在 MSDN 中找不到它。
private void Savecookie(string filename, CookieContainer rcookie)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, rcookie);
stream.Close();
}
文件已被存储文件夹替换,我找不到 binaryformatter 的替代品。我不知道如何序列化文件的数据。
最佳答案
您可以使用 MemoryStream
获取字节数组形式的数据,然后可以将其保存到 StorageFile。
private byte[] SerializeCookies(CookieContainer rcookie)
{
MemoryStream stream = new MemoryStream();
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, rcookie);
stream.Close();
return stream.ToArray();
}
关于c# - 如何在 Metro 中将 cookie 保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11488563/