Encodes the specified binary bytes as BinHex and writes out the resulting text.
using System;
using System.IO;
using System.Xml;
using System.Text;
public class Sample
{
public static void Main()
{
int bufferSize = 1000;
byte[] buffer = new byte[bufferSize];
int readBytes = 0;
using (XmlWriter writer = XmlWriter.Create("output.xml"))
{
FileStream inputFile = new FileStream(@"C:\a.jpg", FileMode.OpenOrCreate,
FileAccess.Read, FileShare.Read);
writer.WriteStartDocument();
writer.WriteStartElement("image");
BinaryReader br = new BinaryReader(inputFile);
do
{
readBytes = br.Read(buffer, 0, bufferSize);
writer.WriteBinHex(buffer, 0, readBytes);
} while (bufferSize <= readBytes);
br.Close();
writer.WriteEndElement();
writer.WriteEndDocument();
}
}
}
Related examples in the same category