title: How to convert utf8 string to utf8 byte array?
body: <p>How can I convert string to utf8 byte array, I have this sample code:</p>
  
  <p>This works ok:</p>
  
  <pre><code>StreamWriter file = new StreamWriter(file1, false, Encoding.UTF8);
  file.WriteLine(utf8string);
  file.Close();
  </code></pre>
  
  <p>This works wrong, file is in ASCII:</p>
  
  <pre><code>byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(utf8string);
  FileStream fs = new FileStream(file2, FileMode.CreateNew);
  fs.Write(bytes, 0, bytes.Length);
  fs.Close();
  </code></pre>
  
  <p>I would like to get byte array what returned by this function:</p>
  
  <pre><code>System.IO.File.ReadAllBytes(path_to_file)
  </code></pre>
  
  <p>because this works ok:</p>
  
  <pre><code>byte[] datab = File.ReadAllBytes(file1);
  FileStream fs2 = new FileStream(file3, FileMode.CreateNew);
  fs2.Write(datab, 0, datab.Length);
  fs2.Close();
  </code></pre>