J
Joey Lee
Hi,
Does anyone know how I am able to write a utf-8 encoded binary string into
binary file?
Currently I am given a UTF-8 string which was read from a gif image.
Here are my functions...
public Byte[] GetDocument(string DocumentName)
{
string strdocPath;
strdocPath = DocumentName;
FileStream objfilestream = new
FileStream(strdocPath,FileMode.Open,FileAccess.Read);
int len = (int)objfilestream.Length;
Byte[] documentcontents = new Byte[len];
objfilestream.Read(documentcontents,0,len);
objfilestream.Close();
return documentcontents;
}
public static string FromUTF8ByteArray(Byte[] characters)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
string constructedString = encoding.GetString(characters);
return (constructedString);
}
public class RawEncoding
{
public static Byte[] GetBytes(string text)
{
Byte[] result = new Byte[text.Length];
for(int i = 0; i < text.Length; ++i)
{
result = (Byte)text;
}
return result;
}
}
Byte[] utf8Bytes =
RawEncoding.GetBytes(FromUTF8ByteArray(GetDocument(FILE_NAME)));
Byte[] finalBytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode,
utf8Bytes);
string fileName = "test.gif";
FileStream fst = new FileStream(file_name, FileMode.Create);
fst.Write(finalBytes, 0, finalBytes.Length);
fst.Flush();
fst.Close();
Thanks
Does anyone know how I am able to write a utf-8 encoded binary string into
binary file?
Currently I am given a UTF-8 string which was read from a gif image.
Here are my functions...
public Byte[] GetDocument(string DocumentName)
{
string strdocPath;
strdocPath = DocumentName;
FileStream objfilestream = new
FileStream(strdocPath,FileMode.Open,FileAccess.Read);
int len = (int)objfilestream.Length;
Byte[] documentcontents = new Byte[len];
objfilestream.Read(documentcontents,0,len);
objfilestream.Close();
return documentcontents;
}
public static string FromUTF8ByteArray(Byte[] characters)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
string constructedString = encoding.GetString(characters);
return (constructedString);
}
public class RawEncoding
{
public static Byte[] GetBytes(string text)
{
Byte[] result = new Byte[text.Length];
for(int i = 0; i < text.Length; ++i)
{
result = (Byte)text;
}
return result;
}
}
Byte[] utf8Bytes =
RawEncoding.GetBytes(FromUTF8ByteArray(GetDocument(FILE_NAME)));
Byte[] finalBytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode,
utf8Bytes);
string fileName = "test.gif";
FileStream fst = new FileStream(file_name, FileMode.Create);
fst.Write(finalBytes, 0, finalBytes.Length);
fst.Flush();
fst.Close();
Thanks