Q:

Writting byte array to txt file gives weird characters (c#)

I have a large array of bytes with different numbers (0-256). First I create .txt file with File.WriteAllText and write few lines of text. After that I want to save my byte array to this file after the text, but when I open it with notepad, there are weird characters in it. Is this a problem with encoding?
String filename = "filename.txt";
String text = "Some metadata........" + Environment.NewLine;
System.IO.File.WriteAllText(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), filename), text);

using (var stream = new FileStream(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), filename), FileMode.Append))
    {
        stream.Write(data_tmp, 0, data_tmp.Length);
        stream.Close();
    }

This is what I see, when I open .txt with notepad:
Some metadata........
øÀþð?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüÀ~ð?øÀ~ð?øÀþà?þà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüÀ~ð?øÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüÀ~ð?øÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþð?øÀþà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ð?üÀ~ð?øÀþð?øÀþà?øÀüàø€üàðüà~ð?üÀ~ð?øÀþà?øÀüà?ø€üàð€üà~ðüÀ~ð?øÀ~ð?øÀ(and so on)

A:

Your question is a vague one. May be you want to encode bytes into some text, say hexadecimal representation?
   String text = 
     "Some metadata........" + 
      Environment.NewLine + 
      String.Join(" ", data_tmp.Select(x => x.ToString("x2"))); // <- encoding 

   System.IO.File.WriteAllText(..., text);

and no FileStream? And so you'll have something like this:
   Some metadata........
   ab 45 25 e8 f0 03     // <- encoded array 

