我的代码:
public static void DoStrumienia (string pString, Stream pStream)
{
if (pStream == null) throw new ArgumentNullException ();
BinaryWriter bw = new BinaryWriter (pStream);
int rozmiar = pString.Length;
bw.Write (rozmiar);
for (int i = 0; i < rozmiar; i++)
{
bw.Write (pString[i]);
}
bw.Flush ();
}
它将字符串写入流,但它使用UTF8编码进行写入。 如何使用UTF16?
答案 0 :(得分:11)
System.Text.Encoding encoding = System.Text.Encoding.Unicode;
BinaryWriter bw = new BinaryWriter (pStream, encoding);