The AppRiver dev team is studying for MSTCS 70-536. These are some observations and notes from those classes.
FileStream v/s StreamReader & StreamWriter
- FS supports random access.
- FS returns byte arrays.
- SR/SW use strings.
- If SR/SW is created with a file path instead of a stream, a FS is implicitly created.
When to use them
If you are working with textual information, use a StreamReader/Writer. Use the FileStream for binary data.
If you need to eek out the maximum performance, the FileStream, StreamReader, and StreamWriter all offer optimiztion parameters, but generally you will not need them.
Posted by Ricky on June 18, 2009 at 2:54 pm
Here’s a little something for ya .. it’ll serialize an object to xml, encrypt it, and save it as a file.
public void SaveToFile(string Path)
{
byte[] data;
using (MemoryStream ms = new MemoryStream())
{
XmlSerializer serializer = new XmlSerializer(typeof(List));
serializer.Serialize(ms, this.Soldiers);
data = ReadByteArrayFromInputStream(ms);
ms.Close();
}
using (FileStream fs = File.Create(Path))
{
Aes aes = Aes.Create();
using (CryptoStream cs = new CryptoStream(
fs,
aes.CreateEncryptor(GetKey(), GetIV()),
CryptoStreamMode.Write))
{
cs.Write(data, 0, data.Length);
cs.Close();
}
fs.Close();
}
}
Posted by Julian Galvis on April 21, 2012 at 11:01 am
Hello, please your help, i Have .NET, but I don´t have the class “Aes” where can i Find it?
Thanks
Posted by Jamison White on April 21, 2012 at 4:56 pm
@julian, I believe Ricky had wrapped classes from the system.security namespace.
http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx
Jamie