我的代码:
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?
System.Text.Encoding encoding = System.Text.Encoding.Unicode;
BinaryWriter bw = new BinaryWriter (pStream, encoding);
请参见此处。